6

Using Laravel-5.8 to send notification, I am getting this error:

Failed to authenticate on SMTP server with username "noblemfd@gmail.com" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 23 ▶
535 5.7.8  https://support.google.com/mail/?p=BadCredentials n13sm8684140wmd.21 - 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 n13sm8684140wmd.21 - 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 n13sm8684140wmd.21 - gsmtp

It was working before, but suddenly began to mis-behave

this is my .env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=noblemfd@gmail.com
MAIL_PASSWORD=****
MAIL_ENCRYPTION=ssl

What do I do?

Thanks

Tim Lewis
  • 27,813
  • 13
  • 73
  • 102
mikefolu
  • 1,203
  • 6
  • 24
  • 57
  • Did you enable 2-factor authentication recently with that gmail account? – Can Celik Feb 27 '20 at 17:19
  • @CanCelik - Yes, I did. I enabled it. – mikefolu Feb 27 '20 at 17:22
  • 1
    Please see the answer for your problem => https://stackoverflow.com/questions/26736062/sending-email-fails-when-two-factor-authentication-is-on-for-gmail – Can Celik Feb 27 '20 at 17:24
  • Does this answer your question? [Sending email fails when two factor authentication is on for Gmail](https://stackoverflow.com/questions/26736062/sending-email-fails-when-two-factor-authentication-is-on-for-gmail) – Spholt Feb 27 '20 at 17:25
  • Does this answer your question? [How to to send mail using gmail in Laravel?](https://stackoverflow.com/questions/32515245/how-to-to-send-mail-using-gmail-in-laravel) – miken32 Feb 27 '20 at 18:45

4 Answers4

6

I have the same your problem today. For months the smtp has been working well and suddently today it gives me the same your error.

For what it worth I simply solved, re-generating the password in google Account -> Security -> App passwords.

It's not the first time this happend to me. Maybe it's some sort of Google protection... but I didn't found evidence of that anywhere. Anyway it's very annoying.

What I wonder is how to catch this kind of error so that we can intervene on time.

nulele
  • 328
  • 3
  • 8
  • 1
    Had the same problem, with Laravel 7. Google is blocking connections. I used my alternative server and was ok. – Xavi Baz Jul 28 '20 at 16:16
  • at the end I connect my Laravel app into Gmail by getting password from app password in security by turning on two-step verification on my second Gmail account – saber tabatabaee yazdi Jun 04 '23 at 21:53
2

I had the same problem under symfony. I went into my google account and generated an application password via this link

generated password app

Attention you will receive a password with several characters.
Example: 'azer tyui opq'

you will need to replace the spaces with the url code.
Example: azer%20tyui%20opq

In my env file. For me that to work

Alprod Grm
  • 33
  • 4
0

1- You must enable two-step verification from the Google Account section, security section, Signing in to Google section.

2- After completing the two-step verification, in the same Signing in to Google section, go to the App passwords section and create a password for the service or device or program you want (PHPMailer or anything else). (On the App passwords page, on the section Click Select app and choose Other option, a text field will be displayed and you should enter PHPMailer or a desired name and then press the Generate button, it will give you a 16 character password.)

3- Copy the displayed password and enter the PHPMailer password in the coding section.

Hamidreza
  • 139
  • 1
  • 12
0

create an app password on google account. you will need to enable two step verification for this feature.

the password will be something like this with spaces in between "** **** ***" ***Remember to put your password from the Gmail app password into the .env file as the mail password.

input this as the email password WITHOUT the spaces in between, but put it in double quotes as below.

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=example@gmail.com
MAIL_PASSWORD="password"
MAIL_FROM_ADDRESS=example@gmail.com
MAIL_FROM_NAME="my app"
MAIL_ENCRYPTION=tls

Youre good to go now.

frankie
  • 1
  • 1