Search code examples
laravelemailgmail

Error sending mail with Laravel app/Gmail in production


I have this error when I try to send mail with Laravel 9 app using Gmail:

Failed to authenticate on SMTP server with username "*************@gmail.com" using the following authenticators: "LOGIN", "PLAIN", "XOAUTH2". Authenticator "LOGIN" returned "Expected response code "235" but got code "534", with message "534-5.7.9 Application-specific password required. Learn more at 534 5.7.9 https://support.google.com/mail/?p=InvalidSecondFactor h4-20020a056830034400b0060603221274sm8631029ote.68 - gsmtp".". Authenticator "PLAIN" returned "Expected response code "235" but got code "534", with message "534-5.7.9 Application-specific password required. Learn more at 534 5.7.9 https://support.google.com/mail/?p=InvalidSecondFactor h4-20020a056830034400b0060603221274sm8631029ote.68 - gsmtp".". Authenticator "XOAUTH2" returned "Expected response code "235" but got code "334", with message "334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==".".

This is my .env configuration.

MAIL_MAILER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=************@gmail.com
MAIL_PASSWORD=************
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=************@gmail.com
MAIL_FROM_NAME="Claims - *****"

I've been reading, and apparently since 5/22/2022 you can no longer activate the option to allow access to less secure applications in Gmail... so, how can we solve this? is this really my problem or another?


Solution

  • google recently changed there security protocol about less secure apps, that's why it's showing the error.