Sending email from web

Discussion in 'ASP.NET / ASP.NET Core' started by bkagan98, Jul 28, 2003.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hello,

    I read all previous postings about sending emails from .net and I am trying to create simple request submission form and keep getting an error: Could not access 'CDO.Message' object.

    Any ideas?

    Thanks.
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    Try this code


    <%@ Page Language="VB" %>
    <script runat="server">
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim mailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
    mailMessage.From = "[email protected]"
    mailMessage.To = "[email protected]"
    mailMessage.Subject = "This is a sample mail sent from ASP.net Mail Component"
    mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
    mailMessage.body = "Congratulation" & VbCrLf & "If you receive this is, your mail component works"
    System.Web.Mail.SmtpMail.SmtpServer = "localhost"
    System.Web.Mail.SmtpMail.Send(mailMessage)
    lblMessage.text = "Mail Sent"
    End Sub
    </script>



    quote:Originally posted by dasp

    Can you post your code?

    </blockquote id="quote"></font id="quote">
     
  3. Takeshi Eto

    Takeshi Eto DiscountASP.NET Staff

    Can you post your code?
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    You won't need that, that was a mistake.


    quote:Originally posted by steurm

    I use practically the same code, but is in C#.
    Any idea how to implement the "Handles MyBase.Load" in C# ?
    thanks !


    --
    Steurm
    www.steurm.net
    </blockquote id="quote"></font id="quote">
     
  5. I use practically the same code, but is in C#.
    Any idea how to implement the "Handles MyBase.Load" in C# ?
    thanks !


    --
    Steurm
    www.steurm.net
     
  6. This component works great. But can anyone tell me why it sends two duplicate messages? Much thanks.
     
  7. Bruce

    Bruce DiscountASP.NET Staff

    Can you post the code?

    quote:Originally posted by housetouror

    This component works great. But can anyone tell me why it sends two duplicate messages? Much thanks.



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

    B.

    DiscountASP.NET
    http://www.DiscountASP.NET
     
  8. Sure, I've added the email component as a sub procedure to alert me with an email ONLY when a new person registers (I'm using a cookie). I'm getting one blank email for when the page loads, then one for when the new info is entered. Thanks for your help

    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
     
  9. Not sure about this, but I'd bet that removing "Handles MyBase.Load" from your AddNewFanEmail method will solve the problem.

    Where in your code are you calling AddNewFanEMail?
     
  10. I got rid of the "Handles MyBase.Load" but it just disabled the component and I get no email sent. The Sub AddNewFanEmail was actually something I accidentally left while expiramenting. I changed it back to Private Sub Page_Load, but it makes absolutely no difference to the email component. Still get two messages.

    The component code currently reads as follows:
    Private Sub Page_Load(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

    Thanks to you all.
     
  11. I am having a similar problem using CDO with ASP. I get 3 duplicate emails. Did you ever resolve this problem?
     
  12. Is it possible that the procedure is called in the page_load event ? I presume that the mail should be sent after clicking a button, so try to put the procedure after a
     
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