none
Can not Send Email Programmatically from ASP.Net RRS feed

  • Question

  • I don't know if I am in the right forum. If not, please redirect to the right one please.

    I tried to send an email programmatically in ASP.Net using smtp.gmail.com as the email server. My code is below:

                    MailMessage MyMailMessage = new MailMessage();
                    MyMailMessage.From = new MailAddress("myAddress@gmail.com");
                    MyMailMessage.To.Add("myDestination@sbcglobal.net");
                    MyMailMessage.Subject = "Programmatic Email";
                    MyMailMessage.IsBodyHtml = true;
                    MyMailMessage.Body = "<table><tr><td>" + "My First Dynamic Email" + "</table></tr></td>";
                    SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com");
                    SMTPServer.Port = 587;
                    SMTPServer.Credentials = new System.Net.NetworkCredential("myAddress@gmail.com", "myGmailPassword");
                    SMTPServer.EnableSsl = true;
                    SMTPServer.Send(MyMailMessage);

    I got an exception as follows:

    The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

    I already enable POP in my gmail setting for outgoing email.

    Any help will be greatly appreciated.



    Goldstar Lee

    • Moved by Sabah ShariqMVP Monday, September 11, 2017 9:44 AM Moved From Visual C#
    Sunday, September 10, 2017 3:52 AM

All replies

  • gmail is a secure email solution so you'll have to figure out how to authenticate the client.

    do a google on the error message you'll get lots of hits and possible solutions.

    The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

    you can also post to the forum.

    http://forums.asp.net/

    • Proposed as answer by laurens vdb Sunday, September 10, 2017 12:48 PM
    Sunday, September 10, 2017 5:41 AM
  • Hi DA924x,

    (1) Before I posted this in the forum, I had already googled it and tried all the suggestions. None worked.

    (2) You asked me to post it in the forums.asp.net. I thought this forum is forums.asp.net. Is it not ? Please clarify.

    Thanks so much.


    Goldstar Lee

    Sunday, September 10, 2017 7:11 PM
  • Hi DA924x,

    http://forums.asp.net is indeed a different forum. I will post it there.

    Thanks again,


    Goldstar Lee

    Sunday, September 10, 2017 7:23 PM
  • Hello Goldstar Lee,

    I have tested you code and it works well base on my side.

    >>The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

    For the above error message ,it might occur due to the following cases.

    case 1:  password is wrong

    case 2:  login from some App

    case 3:  login from the domain other than your time zone/domain/computer (This is the case in most of scenarios when sending mail from code)

    And you could find some solution from there.

    https://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not/26709761#26709761

    You should check it step by step until the error goes.

    Best regards,

    feih_7


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 11, 2017 8:19 AM
  • Hi Goldstar Lee,

    This is Visual C# forum. As your issue is related to Web please ask your question into ASP.Net forum for getting quick response. I am moving your thread to off topic.

    https://forums.asp.net/

    Your understanding and cooperation will be grateful.

    Thanks,
    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Monday, September 11, 2017 9:43 AM