Email Function Problem

Discussion in 'ASP.NET 2.0' started by ashrafcsnet, Jan 27, 2007.

  1. hi all, I'm facing a problem and I need an urgent help please, I can not send any email instead i the debugging mode the parser goes through the function without error!

    I have read the KB here and other articles too but doesn't work [​IMG]

    here is my function:




    Protected Sub sendEmail()


    Dim message As New MailMessage()


    Dim smtpClient1 As New SmtpClient()


    Dim fromAdrs As New MailAddress("[email protected]", "CMC course registration")


    Dim toAdrs As New MailAddress(txtEmailaddr.Text, txtName.Text)


    message.To.Add(toAdrs)


    message.Bcc.Add("[email protected]")


    message.From = fromAdrs


    message.Subject = "Successfully course registered"


    message.Body = "test"


    message.IsBodyHtml = True


    smtpClient1.Host = "localhost"


    smtpClient1.Send(message)


    End Sub





    there is no runtime error, but No emails sent !!





    Thanks
     
  2. You may be missing the System.Net.Mail import or the web.config settings, or both.


    Scott Guthrie has a good blog post about System.Net.Mail in asp.net 2:


    http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx


    For DASP accounts the section in your web.config would look like this:


    <system.net>
    <mailSettings>
    <smtp>
    <network host="localhost" port="25"/>
    </smtp>
    </mailSettings>
    </system.net>
     
  3. Thank you wisemxfor your response, frankly I don't know what to say but it doesn't work [​IMG] this is my code function

    Protected Sub sendEmail()

    Dim message As New MailMessage()
    Dim smtpClient1 As New SmtpClient()
    Dim fromAdrs As New MailAddress("[email protected]", "CMC course registration")
    Dim toAdrs As New MailAddress(txtEmail.Text, txtName.Text)
    message.To.Add(toAdrs)
    message.Bcc.Add(txtEmail.Text)
    message.From = fromAdrs
    message.Subject = "Successfully course registered"
    message.Body = "test msg"
    message.IsBodyHtml = True
    smtpClient1.Host = "localhost"
    smtpClient1.Port = 25
    smtpClient1.Send(message)

    End Sub

    I think there is no need to add the smtp in web.config if it is written in the function (host &amp; port) as above [​IMG]
    I read the scott blog too [​IMG]
    your help is highly appreciated [​IMG]
     
  4. Can we see more of that code? (To help you.)

    i.e., where the input values are passed and when.
    You may be missing the actual event, which can not be diagnosed at this point without the remaining code sections.
     
  5. Bruce

    Bruce DiscountASP.NET Staff

    Another potential problem is Bare LF in your email message. IIS SMTP will NOT deliver email w/ Bare LF in the message body.


    if you still have trouble, create a ticket w/ the From / To address and we can look at the SMTP log to see what happened to the message.


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  6. Thanks all for your response, it doesn't work I'm sorry[​IMG] Bruce if you could explain to me more about the "w/ Bare LF" and what to do exactly...

    Acctually there is aprocedurenamed sendEmail()called when I hit the submit button... kindly see the test.aspx page on www.cmc-training.com/test.aspx

    regards,[​IMG]
     
  7. Bruce

    Bruce DiscountASP.NET Staff

Share This Page