Gmail smtp not working
GMAIL SMTP error: error sending email
Generally, the email sending error occurs when debugging leads to the following error:
The SMTP server requires a secure connection or the client was not authenticated. The response from the server was: 5.5.1 Authentication is required in ASP.Net application.
Therefore, this article will cover the common solutions that can solve the problem.
Incorrect Gmail username or password
You must first check if the username and password provided are correct.
Although Gmail allows you to log in with the username instead of completing the email, when sending an email through the code, you must pass the full email address as the username.
Gmail uses a secure channel to send emails and you must enable SSL security when sending emails through your application.
In .Net, it can be enabled by setting the EnableSsl setting of the SmtpClient to True. For more information, see my article Sending Email Using Gmail's SMTP Mail Server on ASP.Net.
Less secure application settings
If you are sure that your username and password are correct, but you are still getting errors, it means that Gmail has locked your app.
And in such case, you will receive an email similar to the one shown below.
Once you visit the link, you need to modify the settings for the less secure applications and enable access to the less secure applications as shown below.
If solutions n. 1, n. 2 and n. 3 does not work for you, then it could be the problem with the location of the application accessing the Gmail account.
Gmail makes sure that your account is not accessed from another country or geographic location that is far from your usual location, that is, your city when you live and access Gmail on a daily basis.
Generally, the servers are not present in the same country or city where we live, and therefore when you host your website on that server and try to send an email from your application, you may receive an error.
Therefore, to solve it, you will need to open the browser on the server and log in to Gmail. This makes Gmail understand that the server and its IP address belong to you and will allow you to send emails through its application.