PDA

View Full Version : Email component problem


housetouror
09-02-2004, 02:13 AM
I pulled the following code off another thread. Can someone tell me why this email component sends two emails? It sends one for when the page loads(which obviously has no info because nothing has submitted at that point) and another after the submit button is clicked. I thought the If CheckFanEmailAddresses(FanEmail) = false Then would keep it from executing on the initial page load. If there's no explanation, can someone please reccommend a different code? Thank you.

Sub AddNewFanEmail(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FanEmail as String = txtEmailAddress.Text
If CheckFanEmailAddresses(FanEmail) = false Then
Dim mailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
mailMessage.From = "anyone@anywhere.net"
mailMessage.To = "scott@mapleleafmortgage.net"
mailMessage.Subject = "This is an email"
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
mailMessage.body = "The person's email is " & txtEmailAddress.text
System.Web.Mail.SmtpMail.SmtpServer = "localhost"
System.Web.Mail.SmtpMail.Send(mailMessage)
End If

End Sub

bruce
09-03-2004, 01:09 AM
Remove this "Handles MyBase.Load"


[b]quote:Originally posted by housetouror

I pulled the following code off another thread. Can someone tell me why this email component sends two emails? It sends one for when the page loads(which obviously has no info because nothing has submitted at that point) and another after the submit button is clicked. I thought the If CheckFanEmailAddresses(FanEmail) = false Then would keep it from executing on the initial page load. If there's no explanation, can someone please reccommend a different code? Thank you.

Sub AddNewFanEmail(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FanEmail as String = txtEmailAddress.Text
If CheckFanEmailAddresses(FanEmail) = false Then
Dim mailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
mailMessage.From = "anyone@anywhere.net"
mailMessage.To = "scott@mapleleafmortgage.net"
mailMessage.Subject = "This is an email"
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
mailMessage.body = "The person's email is " & txtEmailAddress.text
System.Web.Mail.SmtpMail.SmtpServer = "localhost"
System.Web.Mail.SmtpMail.Send(mailMessage)
End If

End Sub
</blockquote id="quote"></font id="quote">

B.

DiscountASP.NET
http://www.DiscountASP.NET

housetouror
09-05-2004, 01:11 AM
Thanks Bruce, but that makes it not work at all. Do you have any other ideas?

steurm
09-06-2004, 02:08 AM
Is there any change that sending your mail is situated in a page_load event ? If so, put If not Page.IsPostback before the call to your Sendmail function.



--
Steurm
www.steurm.net/steurm

housetouror
09-07-2004, 03:27 AM
Yes Steurm, that works great. Thank you.