In this article I will explain how to resolve the error: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required in ASP.Net Application.
The following error occurs when you try to send email using Gmail credentials in your ASP.Net application.
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
Following are the possible solutions in order to resolve the error.
1. Incorrect Gmail Username and/or password
First you must check whether the Username and Password supplied are correct.
Though Gmail allows you to sign in with Username instead complete Email but when sending email through code you need to pass the complete Email address as Username.
2. SSL setting
Gmail uses secure channel for sending emails and hence you need to enable SSL security while accessing Gmail Mailbox through your application.
3. Less Secure Apps setting
If you are sure that your Username and Password are correct, but you are still getting errors then it means that Gmail has blocked your application.
And in such case, you will receive an email similar to what is shown below.
Note: If you have not received any email, then use the following link to enable Less Secure Apps setting.
Once you visit the link, you need to modify the Less Secure Apps setting and Turn On access to Less Secure Apps as shown below.
4. Two Step Authentication
If Two Step Authentication is enabled for your Gmail Account, then the Less Secure Apps settings will not be available and you won’t be able to send emails using your Gmail Password.
Thus, in such scenario, you will need to generate App Password for your Gmail Account using the following link.
1. You will see the following page.
2. Select Other option in App DropDownList.
3. Give the App, a suitable name and click the Generate Button.
4. Once generated, copy and save the Password (in Yellow Box) somewhere and click Done.
5. The App will be visible, but its Password will not be visible again. If you ever forget the Password, delete the App and create a new one.
5. Application Location
If the solutions #1, #2, #3 and #4 are not working for you then it might be the issue with the location of the Application accessing the Gmail account.
Gmail makes sure that your account is not being accessed from some other Country or geographical location which is far from your routine location i.e. your city when you live and access Gmail daily.
Generally, the servers are not present in the same country or city where we live in and hence when you host your website on such server and try to send email from your application you might receive error.
Thus, in order to resolve it, you will need to open browser on the server and login into Gmail. This makes Gmail understand that the server and its IP Address belongs to you and it will allow you to send emails through your application.