The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated

I am working on ASP.Net Solution, and when I tried to send an automated email using C#, I got the below error:

Server returned status code 530 – The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated

Exception details:
Message: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated
Type: System.Net.Mail.SmtpException
Stack trace:
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at Microsoft.Exchange.Tools.ExRca.Tests.SmtpMessageTest.PerformTestReally() 

The SMTP server requires a secure connection or the client was not authenticated

This issue usually occurs in case of

  • The account used to sent email is not authenticated on the Exchange.
  • Send – Receive connectors are not configured properly.

Solution

To overcome this issue you should do the following:

  • Check with your Exchange administrator to permit the required permission for the e-mail account to send an e-mail.
  • Review the default receive connector and make sure you have selected “anonymous” users on the permissions groups tab.

If everything is ok, and there is no issue for the account permission, and you still face this issue, so try to modify your code by setting the “UseDefaultCredential” to false and providing the correct username and password.

smtpClient.UseDefaultCredentials =false;
smtpClient.Credentials = new System.Net.NetworkCredential(From, Password);
The SMTP server requires a secure connection or the client was not authenticated

Note: SmtpClient is using the app pool identity account to connect to SMTP host.

App Pool Identity is a domain account

If the app pool identity is a domain account, so you should provide it the appropriate permission to send an e-mail as we earlier mentioned.

App Pool identity is not a domain account

If the app pool identity is not a domain account, so you should change to a domain account that has sufficient permission to send an e-Mail.

Additionally, make sure that you have enabled SSL before running “smtpClient.Send()

smtpClient.EnableSsl = true;

Send an email using C#

The final code should look like

using (MailMessage email = new MailMessage())
{
    // specify your email
    email.From = new MailAddress("from@email");
    email.To.Add("to@email");
    email.Subject = "send email using C#";
    email.Body = "email body";
    //email.Attachments.Add(new Attachment("the physical file path"));
    using (SmtpClient smtpClient = new SmtpClient("SMTP Server", Port))
    {
        smtpClient.Credentials = new NetworkCredential("account", "password");
        smtpClient.EnableSsl = true;
        smtpClient.Send(email);
    }
}

Conclusion

In conclusion, we have fixed the “The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated” issue.

Applies To

  • ASP.NET
  • .NET Framework.
  • C#.
You may also like to read
Have a Question?

If you have any related questions, please don’t hesitate to ask it at deBUG.to Community.

2 thoughts on “The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated”

  1. http://sitngostrategie.wordpress.com/

    This is the perfect website for anyone who would like to
    find out about this topic. You know so much its almost tough to argue
    with you (not that I personally will need to…HaHa). You certainly put
    a new spin on a subject which has been written about for years.
    Wonderful stuff, just great!

  2. Homemade Bubble Bath

    This design is incredible! You obviously know how to keep a
    reader entertained. Between your wit and your videos, I was almost moved to start myy oown blog
    (well, almost…HaHa!) Fantastic job. I rally enjoyed what
    you had to say, and moore than that, hoow you presented it.
    Too cool!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top