Search code examples
symfonygmailswiftmailer

Symfony Swiftmailer Gmail - Not working on remote server


I have configured symfony to send emails using gmail:

// .env file
MAILER_URL=gmail://<email>:<password>@localhost?encryption=tls&auth_mode=oauth

When I run ./bin/console swiftmailer:email:send on my local dev machine the email is sent out.

I have the same setting on a staging server and when I run ./bin/console swiftmailer:email:send on this machine I get an error

Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username "username" using 1 possible authenticators

I have turned on access for less secure apps in gmail.

I don't understand why it would authenticate on my local machine and not the staging server.


Solution

  • I had to go to the following link:

    https://accounts.google.com/DisplayUnlockCaptcha

    and then click the button.

    I found this link by digging around on SO. Unfortunately, it was not documented or mentioned by google, but it solved my issue.