Forums

Gmail SMTPAuthenticationError

Hi,

I have a script which sends a daily email from a gmail account. It was running without issue for the past few months.

As of yesterday I am getting the following error whenever I try to send the email

smtplib.SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt0\n5.7.14 Nf5iHU4zyx5ZW3rFwf2TKdUfRC8D8j8ywHX9TExe13NHK5_XaK68YW13omsI51N7onzZMc\n5.7.14 6DqghiR8GlJFk7gik27RCQUbgFjSKrTtdwy37hkN9j0HIrzoxopRaVpLy7D__MBQPAeh-f\n5.7.14 FjYRaTZMQ9vIlAJtQ14eC3G2VDpOVP1X0PviZKllqjODJqWzNpjn8iR3TPypN7o4EnhDvy\n5.7.14 s1yKKBgzPVGuh41gxnR74oXxDsEo0> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 x79sm5967992qka.37 - gsmtp')

Allowing less secure apps is enabled for the gmail account.

Do you know what could be causing the error?

Thnak you!

Hi there,

We just deployed new servers yesterday. It could be that gmail doesn't recognize the new servers and so needs additional verification to continue. You would have to login to your google security dashboard and confirm the login etc.

Conrad

Hi Conrad,

Thanks for your reply. I confirmed that the login attempts came from me in the google security dashboard but I'm still getting the same error with my script this morning.

Where is the script running? If it's from a console, you can try logging in to your Google account using the text-only lynx browser from the console where it would run -- that might persuade Google that the login is OK.

Hi giles, thanks for the suggestion. I'm running the script as a scheduled task. I can actually log in and send an email when using the console. I also logged into my account using the lynx browser but I'm still having the same issue when I try to run my script as a scheduled task.

hmm- there are a bunch of different servers that your code is running on. and the lynx browser you used in one console may not apply for other consoles (and doesn't apply for the servers used to run your tasks). So it is possible that you may have to confirm more than one ip address etc.

The other thing you could try is to use app specific passwords instead of using the "less secure apps" option.

Using app specific passwords seems to have solved this problem. Thanks for your help guys!

             / ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄\  
<<<<<<:>~  <   Yay!           |
             \_________/

Hi!

I have a same problem - SMTPAuthenticationError with gmail. But gmail say your account can't generate the app passwords.

What can I do?

May be you can suggest some another free mail server?

You probably need to setup two factor auth before you can generate app specific passwords.

It's working now!

  1. Set up the EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
  2. Turn on gmail 2-factor
  3. Generate the app specific password

Thank you!

Hi,

I have exactly the same problem. won't be able to send email from my gmail account due to authorization error.

Please advise.

Thank you.

Are you using an app-specific password?

I'm getting "smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?....." Whenever i try to send mail from my Flask application. It was running fine on the localhost but on pythonanywhere same settings are not working.

app.config.update(dict( DEBUG = False, MAIL_SERVER = 'smtp.gmail.com', MAIL_PORT = 587, MAIL_USE_TLS = True, MAIL_USE_SSL = False, MAIL_USERNAME = username, MAIL_PASSWORD = password, ))

Google tend to be a bit stricter when they detect that a login is coming from a cloud service than they are when it is coming from a residential ISP. The best solution is to use an app-specific password -- that is, a password that you create specifically for your website's code that is different to the one you use to log in to Gmail normally. This Google help page has more info.

i'm using Flask-Mail i had the same smtpAuthenticationError this is my code. (app.config['MAIL_SERVER'] = 'smtp.gmail.com' app.config['MAIL_PORT'] = 465 app.config['MAIL_USERNAME'] = 'username' app.config['MAIL_PASSWORD'] = 'password'

app.config['MAIL_USE_TLS'] = False app.config['MAIL_USE_SSL'] = True)

i turn on les secure account setting, i turn on 2 step verfication and i get an 16 digit app passowrd in gmail and then what should i do with the app password?

Substitute ‘password’ in your code for the 16 digit password.

Thank you so much its working

@dreid254 +1 :)