afoysal's avatar

Send mail from Local host

I am trying to send email from local host to Gmail. But I am getting below error.

Swift_TransportException
Failed to authenticate on SMTP server with username "[email protected]" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials v9-20020a17090a00c900b00253305f36c4sm4715108pjd.18 - gsmtp ". Authenticator PLAIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials v9-20020a17090a00c900b00253305f36c4sm4715108pjd.18 - gsmtp ". Authenticator XOAUTH2 returned Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials v9-20020a17090a00c900b00253305f36c4sm4715108pjd.18 - gsmtp ". 

My email settings in .env file is like below.

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=123456789
MAIL_ENCRYPTION=TLS
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
0 likes
2 replies
LaryAI's avatar
Level 58

The error message suggests that the authentication credentials provided are incorrect. Double-check that the email and password are correct. Additionally, ensure that the Google account has allowed access to less secure apps.

To enable access to less secure apps, follow these steps:

  1. Go to the Google account security page: https://myaccount.google.com/security
  2. Scroll down to the "Less secure app access" section and click on "Turn on access (not recommended)".
  3. Toggle the switch to enable access for less secure apps.

If the issue persists, try generating an app password for the Gmail account and use that instead of the account password.

To generate an app password, follow these steps:

  1. Go to the Google account security page: https://myaccount.google.com/security
  2. Scroll down to the "Signing in to Google" section and click on "App passwords".
  3. Select "Mail" and "Other (custom name)" from the dropdowns.
  4. Enter a custom name for the app password and click on "Generate".
  5. Copy the generated password and use it as the MAIL_PASSWORD in the .env file.

If the issue still persists, try using a different email service provider or contact Google support for further assistance.

Example .env file with app password:

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=generated_app_password
MAIL_ENCRYPTION=TLS
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
tisuchi's avatar

@afoysal it seems your credential is not accepted. Make sure you have used the right credential.

Refering to this docs I believe the value for MAIL_PORT and MAIL_ENCRYPTION should be like this.

MAIL_PORT=465
MAIL_ENCRYPTION=ssl

Please or to participate in this conversation.