Home >Backend Development >Golang >Why Am I Getting the '535 5.7.8 Username and Password not Accepted' Error When Sending Emails via SMTP?

Why Am I Getting the '535 5.7.8 Username and Password not Accepted' Error When Sending Emails via SMTP?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-21 13:19:09317browse

Why Am I Getting the

Failed Email Delivery: Resolving the "535 5.7.8 Username and Password not Accepted" Error

When attempting to configure an email sending function using the SMTP protocol, you may encounter the error "535 5.7.8 Username and Password not accepted. Learn more at 5.7.8 https://support.google.com/mail/?p=BadCredentials." This error occurs despite having enabled Allow less secure apps and inputting seemingly correct credentials.

Addressing the Issue

The underlying cause of this error lies with Google's attempt to enhance account security. To resolve the issue and ensure successful email delivery, follow these steps:

1. Enable 2FA Authentication

If not already enabled, activate 2-step verification for your account: https://myaccount.google.com/security

2. Generate an App Password

Navigate to https://security.google.com/settings/security/apppasswords and create an app password. This is a 16-digit passcode that grants limited access to your Google account specifically for the purpose of email sending through the SMTP protocol.

3. Use the App Password in Your Code

Replace the constant string "somecrazypw" in your SendContactUsForm function with the app password generated in step 2. This will ensure that your email sending function uses the appropriate credentials to authenticate with Google's SMTP server.

Conclusion

By following these steps, you can enable secure and reliable email delivery through the SMTP protocol, avoiding the "535 5.7.8 Username and Password not accepted" error. Remember, it is important to maintain secure account practices by enabling both 2FA and using app passwords for specific applications.

The above is the detailed content of Why Am I Getting the '535 5.7.8 Username and Password not Accepted' Error When Sending Emails via SMTP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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