Email component problem

Discussion in 'ASP.NET / ASP.NET Core' started by housetouror, Sep 2, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. 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 = "[email protected]"
    mailMessage.To = "[email protected]"
    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
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    Remove this "Handles MyBase.Load"


    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 = "[email protected]"
    mailMessage.To = "[email protected]"
    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
     
  3. Thanks Bruce, but that makes it not work at all. Do you have any other ideas?
     
  4. 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
     
  5. Yes Steurm, that works great. Thank you.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page