Send email from Gmail with SMTP authentication but got "5.5.1 Authentication Required" error

Programming, error messages and sample code > sample code
You may get the error message mentioned below when you use your Gmail account to send an email message through your script
 
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.


Solution:

1. Please make sure you have set SMTP authentication correctly in your script, for sample code, please click here

2. If there is no problem with your SMTP script, but you still got the message mentioned above, then the error might occur due to the following cases:

 

case 1: when the password is wrong

case 2: when you try to login from a new App/domain/computer(This is the case in most scenarios when sending mail from code)

There is a solution for each

solution for case 1: Enter the correct password.

solution for case 2: generate an App Password for your SMTP codes

But what if you don't have access to the production server. try the below as well

You have to enable login from another timezone/IP for your google account.

To do this follow the link https://g.co/allowaccess and allow access by clicking the continue button.

And that's it. Here you go. Now you will be able to log in from any of the computers and by any means of the app to your google account.