SwiftMailer not send mail with Google App account

1.8k views Asked by At

I'm using Symfony and I'm trying to send an email with swiftmailer. I have an account set up with google app ([email protected]) and when I try to send shows me the following error:

Failed to authenticate on SMTP server with username "[email protected]" using 2 possible authenticators

I tried it with my personal gmail account and send the message correctly with the same settings. Just change the username and password.

# Swiftmailer Configuration
swiftmailer:
    transport: smtp
    host:      smtp.gmail.com
    username:  [email protected]   #[email protected]
    password:  google_app_password       #gmail_password
    auth_mode: login
    port:      587
    encryption: tls

I've been searching the internet and I've found this page from Google, where I can change the access to less secure applications. https://www.google.com/settings/security/lesssecureapps

In my gmail account this option is active, but if I turn shows me the same error when sending email. I've been trying to change this setting in google app account but it tells me that this option is not available for google app.

Any idea to send emails from this account by google app? I have to set something else?

EDIT It seems Gmail prefers OAuth, Swiftmailer supports this authentication mech but its not really documented.

https://developers.google.com/gmail/xoauth2_protocol https://github.com/swiftmailer/swiftmailer/blob/5.x/lib/classes/Swift/Transport/Esmtp/Auth/XOAuth2Authenticator.php

Any idea how I use it in Symfony?

1

There are 1 answers

1
BT643 On

Have you tried setting the transport parameter to gmail as mentioned in the cookbook? http://symfony.com/doc/current/cookbook/email/gmail.html

# Swiftmailer Configuration
swiftmailer:
    transport: gmail
    username:  your_gmail_username
    password:  your_gmail_password