Home > Backend Development > Golang > How to Fix SMTP Error 535: Username and Password Not Accepted for Gmail in Go?

How to Fix SMTP Error 535: Username and Password Not Accepted for Gmail in Go?

DDD
Release: 2024-12-11 16:06:12
Original
656 people have browsed it

How to Fix SMTP Error 535: Username and Password Not Accepted for Gmail in Go?

SMTP Error 535: Resolving "Username and Password Not Accepted" for Gmail in Go

In the provided code, you're encountering an error when sending emails with SMTP in Go. The error message, "535 5.7.8 Username and Password not accepted," indicates that Gmail is rejecting your credentials.

To resolve this issue, consider the following steps:

1. Enable Two-Factor Authentication:

Ensure that you have enabled two-factor authentication (2FA) for your Gmail account at myaccount.google.com/security. 2FA adds an extra layer of security by requiring a code sent to your phone upon login.

2. Generate an App Password:

Instead of using your regular password, create an app password at security.google.com/settings/security/apppasswords. App passwords allow you to grant specific access to third-party applications without exposing your main password.

3. Use the App Password:

In your Go code, update the "pass" variable to use the app password you generated in step 2.

4. Modify the Authentication Mechanism:

Currently, you're using the PlainAuth function to authenticate. Instead, try using OAuth2 authentication for improved security and reliability. You can find more information on using OAuth2 with Gmail here: https://developers.google.com/identity/protocols/OAuth2

The above is the detailed content of How to Fix SMTP Error 535: Username and Password Not Accepted for Gmail in Go?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template