Sending emails in

Discussion in 'Site Programming, Development and Design' started by lionelthomas, Oct 12, 2009.

  1. Am using this example:

    protected void Page_Load(object sender, EventArgs e)
    //create the mail message
    MailMessage mail = new MailMessage();

    //set the addresses
    mail.From = new MailAddress("");

    //set the content
    mail.Subject = "This is an email";
    mail.Body = "This is from using C sharp with smtp authentication.";
    //send the message
    SmtpClient smtp = new SmtpClient("");

    NetworkCredential Credentials = new NetworkCredential("", "password");

    lblMessage.Text = "Mail Sent";

    This script worked when the "mail.To.Add" is set to an authenticated email.
    Cannot send an email to an unauthenticated email such as ""

    How does one send such an email?
  2. Ray


    What is the error message you're getting? Did you try using another email other then a gmail account?
  3. Im not sure if I am missing it, plus I know it is an example. But have you checked that you set smtp.Credentials = Credentials?
  4. There is no error message.
    Am able to send an email from any email address to an email address that is in my domain ie. So, I have set up a contact page at www.lionel that works(not yet pretty) .But when I send an email to any address that is not in my domain then it executes but the email is not received. Have tried several.
  5. Ray


    Try sending to another email address that is not gmail. Make sure the from address is valid. Remember the From address or also the 'Reply-To' address is also important because it is the email address the server will use if it needs to send a bounce back message. Bounce back messages are very helpful when troubleshooting email problems.
  6. Ray


    The error message does indicate that you are not passing the correct SMTP authentication. Remember, before you can send out through our SMTP server, the SMTP server will have to authenticate you. Try looking at this kb article again as an example code to send out email through your web pages.
    Last edited by a moderator: Oct 14, 2015
  7. It appears that the from address can be any string in email address format.

    Sent an email from to (valid address in my domain)

    Email received with in From: field

    My point exactly. The "to address" has to be authenticated but the "from address" doesn't.
    I want to send an email from to
    Is there a mode that will authenticate the "from address" to allow me to send to an unauthenticated "to address"
  8. As Ray said you the SmtpClient is likely not properly logging into the SMTP server, which means that the SMTP server will not relay the message to another domain. Which is why works, but does not.

    Looking at the code snippet you pasted, the Credentials variable is not being assigned to the smtp client.

    If you change:

    NetworkCredential Credentials = new NetworkCredential("", "password");

    NetworkCredential Credentials = new NetworkCredential("", "password");
    smtp.Credentials = Credentials;

    then if they have things set up the way I would expect it should allow you to send mail to
  9. Thanks Sean Lynch,
    How does one learn this stuff? Is there a place I can read about this without having to tiptoe through the minefield. It takes me hours to learn by trial and error.
    So the SMTP client needs to be authenticated and not just the addresses.
  10. Not really sure, I have learned a large part with trial and error. is a good place for questions like this.

    And Ray, your KB article has the same problem I pointed out. Since the code that Lionel posted is from the KB article that you posted.

    Edit: Only the C# version of it, the VB.Net one is right.
  11. Ray


    Thanks Sean, I'll make sure to update our KB article.

Share This Page