Home > Backend Development > Golang > Why Am I Getting SMTP Authentication Error 535: Username and Password Not Accepted with Gmail?

Why Am I Getting SMTP Authentication Error 535: Username and Password Not Accepted with Gmail?

Linda Hamilton
Release: 2024-12-19 02:54:09
Original
778 people have browsed it

Why Am I Getting SMTP Authentication Error 535: Username and Password Not Accepted with Gmail?

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...
Copy after login

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:

  1. Enable 2-Factor Authentication (2FA)
  • Navigate to https://myaccount.google.com/security and enable 2FA if not already.
  1. Generate an App Password
  • Visit https://security.google.com/settings/security/apppasswords
  • Select the "Mail" option for the device and application
  • Generate a 16-digit App Password

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))
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template