Sending E-mail from web site

Discussion in 'Email' started by MervNorton, Jan 28, 2014.

  1. I am trying to send an email from my web site, MervNorton.com I am using the code provided by DiscountASP, How to send email in ASP.NET 2.0 - SMTP authentication.

    The code works. I then created a simple input form that only includes the addressees email address and a Message. The following is the line of code I changed and the line of code after changing.

    mail.To.Add( "[email protected]" ); Original

    mail.To.Add( txtEmail ); Revised

    txtEmail is the ID of a Email TextBox on the Input Form.

    Go to www.MervNorton.com and click on my photo to access the Input Form and enter your own Email Address and you can see the problem.


    If I can solve this problem I can create a new Input Form with additional variables.


    What is my problem and what is the solution.
     
  2. FrankC

    FrankC DiscountASP.NET Staff

    try txtEmail.text instead.
     
  3. I tried that and get the following message:

    Compiler Error Message: CS0103: The name 'txtMail' does not exist in the current context

    Source Error:

    Line 13: mail.Subject = "This is a test message" ;
    Line 14: mail.Body = "If you can see this mail, your SMTP service is working" ;
    Line 15: mail.To.Add( txtMail.Text );
    Line 16: SmtpClient smtp = new SmtpClient( "smtp.MervNorton.com" );
    Line 17:
     
  4. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    Spelling error. It's txtEmail.Text, not txtMail.txt as in your code. So either change your code or the ID of your control.
     
  5. My code is correct. My post was incorrect.
     
  6. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    I'm checking right now, and your post is correct:

    Line 15: mail.To.Add(txtMail.Text);

    It should be mail.To.Add(txtEMail.Text);

    Recompile your application and re-upload if necessary.
     
  7. Corrected txtmail.Text to txtemail,Text with same results.
     
  8. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    I'm not sure if the problem was because you had extra white spaces in parts of your code, spelled the ID "txtEmail" incorrectly (it was a small m, not capital M), or if it was because you put the code in the Page_Load event handler, causing the control not to be rendered first prior to execution of sending email, but I have debugged all of that and placed a working script in your account that you can review. The file name is TestEmail2.aspx.
     
  9. I hank you for your support but I do not know what you mean by MY ACCOUNT.
     
  10. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

Share This Page