11
votes

I am having some hard time getting my PHP script to send emails with a SMTP Gmail account. I am using PHP and Symfony2 SwiftMailer, but it seems that the problem lies with my Gmail account configuration. In my logs, I end up with the following error message:

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

Luckily, I had another Gmail account working with another application, seemlessly. Rescuing these parameters (user and password) on my new box, eveything works just fine.

in parameters.yml I have (working fine):

parameters:
    mailer_transport: gmail
    mailer_host: ~
    mailer_user: [email protected]
    mailer_password: old-password

And here is the version giving auth error message:

parameters:
    mailer_transport: gmail
    mailer_host: ~
    mailer_user: [email protected]
    mailer_password: new-password

Needless to say I have checked, rechecked and checked yet again user and password.

I reviewed my Gmail account settings under "Forwarding and POP/IMAP" in my new account: I could find nothing about SMTP.

Searches made me aware some captcha policy may interfere with SMTP accounts. I read here that I should try to enter a captcha phrase, which I do here, and get the nice message:"Account access enabled", "Please try signing in to your Google account again from your new device or application."

Trying again. No luck.

All this is happening from my local dev environment (both OK mails, and NOT OK mails).

How I could get to use SMTP with a newly created Gmail Account ? Any idea ?

3

3 Answers

30
votes

Actually, double-checking my inbox, I saw I received a mail from Google explaining someone was trying to enter my account. There, I found a link to the configuration parameter I was looking for:

https://www.google.com/settings/security/lesssecureapps

==> I just had to check: "Make my account less secure.", and was able to get mails sent.

In the mean time, I have found that Gmail SMTP service is getting pretty unrelyable and introduces captcha every now and again (here). I seems there is not much you can do about it. On the other hand, I read stronger passwords seem to help in some cases (here).

I must also say that with a newly created account, I was not able to get this working. Even unchecking the "make my account overly secure" option. It really looks like Gmail is phasing out its SMTP service.

UPDATE

I wanted to mention that there are some excellent and free (or very, very cheap for high volumes) alternatives for sending emails. For example, you could check Mandrill, SendGrid or Amazon SES, among others.

2
votes

Using the link https://www.google.com/settings/security/lesssecureapps gave me the message: this setting is disabled by your administrator.

I had to go to admin.google.com and login with the same account details and look for the same setting there. Full url was https://admin.google.com/AdminHome#ServiceSettings/notab=1&service=securitysetting&subtab=lesssecureappsaccess

Then the first link worked, so also there I enabled less secure apps. Now I was able to use Gmails SMTP.

0
votes

Maybe this helps someone: I had the same encounter with gmail, but in my case, when I logged into the gmail account that I configured in my code as SMTP mail sender user, I was greeted by a warning message saying that somebody tried to use my user and pass and that attempt was blocked (hence my error message). It asked me to confirm if that was me or not, so after I clicked the 'That was me' button and tried my code again all worked fine.