Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script Sending mails with Gmail: Failed to authenticate on SMTP server

Tags:

email

smtp

gmail

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 ?

like image 550
mika Avatar asked Mar 17 '15 12:03

mika


2 Answers

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.

like image 55
mika Avatar answered Sep 24 '22 17:09

mika


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.

like image 29
RuudvK Avatar answered Sep 22 '22 17:09

RuudvK