Whenever you want to integrate the Gmail SMTP Server with Gmail Credentials, the Gmail account may need the permission to allow the connection. If the permission is not set then the below error was thrown.
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....
There may be several reason for this, we discuss all the reason step by step so it can help you.
Incorrect Username/password of Gmail
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.
SSL setting
Gmail uses secure channel for sending emails and you need to enable SSL security while sending emails through your application. In .Net it can be enabled by setting EnableSsl setting of the SmtpClient to True. For more information please refer my article Send email using Gmail SMTP Mail Server in ASP.Net.
Less Secure Apps setting
If you are sure that your Username and Password are correct, but you still get errors then it means that Gmail has blocked your application. And in such case you will receive an email like below screenshot.
If you have not received any email then please follow below link and allow less secure apps. https://myaccount.google.com/lesssecureapps
Application Location
If the solutions of above are not working 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 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.
Post a Comment