Saturday, March 24, 2012

smtpclient send twice the mail

Hi,

here is the code placed into the .vb file:

Imports System.Net.Mail

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub SendMail(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objEmail As New MailMessage()

Response.Write("Adding FROM values: " & txtEMail.Text & " " & txtName.Text & "<br />")
objEmail.From = New MailAddress(txtEMail.Text, txtName.Text)
Response.Write("Empty TO list<br />")
objEmail.To.Clear()
Response.Write("Found: " & objEmail.To.Count.ToString & "email<br />")
Response.Write("Adding TO address<br />")
objEmail.To.Add(New MailAddress("dumortier.marc@dotnet.itags.org.telenet.be", "Marc Dumortier"))
Response.Write("Adding Subject<br />")
objEmail.Subject = "Test EMail"
Response.Write("Adding Body<br />")
objEmail.Body = "Test d'eamil depuis une page apsx" & vbCrLf & vbCrLf & txtCmts.Text

Dim SmtpSvr As New SmtpClient
SmtpSvr.Host = "uit.telenet.be"
SmtpSvr.Send(objEmail)
Response.Write("Your E-mail has been sent sucessfully to: " & objEmail.To.ToString & "<br />")
End Sub

Protected Sub ClearFields(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
txtName.Text = ""
txtEMail.Text = ""
txtCmts.Text = ""
End Sub
End Class

When i click the submit button i receive twice the email but i don't know why, can someone help me?

Avenger68 wrote:

Handles Button1.Click

With this line in your event handler, if you also specify in your button as onclick, the sub will run twice.

<asp:button onclick="dosomething"> as an example. Either take out the Handles button1.click or take out your onclick event.


Hi,

thanks this was the problem.

0 comments:

Post a Comment