SMTP Authentication Error 535: Username and Password Not Accepted with Gmail
When attempting to send emails from a localhost using the provided function, users may encounter the following error:
smtp error: 535 5.7.8 Username and Password not accepted for gmail...
Despite ensuring valid credentials and enabling "Allow less secure apps," this issue can still occur.
Cause
The error indicates that the authentication credentials used are incorrect or not authorized. Google has recently implemented stricter security measures, which can prevent email sending from certain apps.
Solution
To resolve this issue, it is recommended to:
Using the App Password
Replace the regular password in the SMTP authentication code with the generated App Password. The updated code will look like this:
err = smtp.SendMail("smtp.gmail.com:587", smtp.PlainAuth("", from, appPassword, "smtp.gmail.com"), from, []string{to}, []byte(msg))
Note: An App Password provides restricted access to your Google Account specific to the app or device.
The above is the detailed content of Why Am I Getting SMTP Authentication Error 535: Username and Password Not Accepted with Gmail?. For more information, please follow other related articles on the PHP Chinese website!