Forums

smtplib.SMTPAuthenticationError Issue

Hi , While sending mail from Gmail Account I am facing this issue,although less secure app access is on.

Traceback (most recent call last):
  File "sending_mail_snippet.py", line 27, in <module>
    s.login(fromaddr,"criccdar@1234")
  File "/usr/lib/python3.6/smtplib.py", line 730, in login
    raise last_exception
  File "/usr/lib/python3.6/smtplib.py", line 721, in login
    initial_response_ok=initial_response_ok)
  File "/usr/lib/python3.6/smtplib.py", line 642, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbs\n5.7.14 L2007kDCe4ke
ChXS7TDZA_ZT0abh3oBPrJbMicRldQI83K0E3ORDkcqEN23x8turoFV3f\n5.7.14 wJOhcs24MXlJy_-kYgPZ_JA1S6FXEqua4mr8w2FSqJdRY8lhKBGmbKN1NJzHxfSL>\n5.7.1
4 Please log in via your web browser and then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 l95s
m1002890qte.36 - gsmtp')

[edit by admin: formatting]

Check out the "Use Gmail's SMTP servers" section of this help page -- in particular the part on app-specific passwords.

I get this same problem ! In dev mode with DEBUG = True it is working ok. In Prod mode with DEBUG = False it is not working because of the Server Error (500)

File "/usr/lib/python3.7/smtplib.py", line 642, in auth
  raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv\n5.7.14 YvzmuwTqKFmdOtyqVnSEbWeYUN3hob1swJd9YISfeuo9SFWtPcFqA2YBwwQmd4Wx10w2d\n5.7.14 rvp5oU95Tu50Vubs9TYGpXG86ZWKha7IDxT3UDAsM8y7zupbAJPuBQ3_lrDrdyKA>\n5.7.14 Please log in via your web browser and then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 f4sm23479179wrs.34 - gsmtp')

The email and password are correct and I have enabled access to less secure apps on my account.

Did you follow the instructions in the error message and go to that URL to authorise it?

[formatted by admin]

File "/home/pondicherryfashionmodels/.virtualenvs/flaskk/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "./main.py", line 50, in register
    mail.send(msg)
  File "/home/pondicherryfashionmodels/.virtualenvs/flaskk/lib/python3.7/site-packages/flask_mail.py", line 491, in send
    with self.connect() as connection:
  File "/home/pondicherryfashionmodels/.virtualenvs/flaskk/lib/python3.7/site-packages/flask_mail.py", line 144, in __enter__
    self.host = self.configure_host()
  File "/home/pondicherryfashionmodels/.virtualenvs/flaskk/lib/python3.7/site-packages/flask_mail.py", line 165, in configure_host
    host.login(self.mail.username, self.mail.password)
  File "/usr/lib/python3.7/smtplib.py", line 730, in login
    raise last_exception
  File "/usr/lib/python3.7/smtplib.py", line 721, in login
    initial_response_ok=initial_response_ok)
  File "/usr/lib/python3.7/smtplib.py", line 642, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt\n5.7.14 8foqurWtmBPcVQFSeV5JTTQ236AB1ZtDGpbKeidjlgYBK06N7q7Py3lAc3Ac1rgKYHihZ\n5.7.14 VYSY3XqE0bB9-mxEr9udEqZbPUpkzjmz9YA5amurKhvBHGs0oGKWFQO85Ty5acsN>\n5.7.14 Please log in via your web browser and then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 q7sm2534262qki.17 - gsmtp')

i'm facing the same error, but my project is in flask i'm enabled to less secure apps on my account

Did you follow the link in the error?

i don't know what to do?

I see that we're corresponding about this over email too, so we'll answer there to avoid duplication.

i turn ON 2step verification and i got an 16 digit app password and then what should it do?

According to our conversation in emails, the issue seems to be solved.

what was the solving error??

Take a look at Gmail App-Specific Passwords | PythonAnywhere help

Follow the steps in this link, Worked for me:- Link

You have to correctly setup your smtp on your gmail account . Correctly place the port number the host id and the 16 digit password. If you are in django put the id and password of your smtp server in the settings.py file.
An example-

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587 
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'the gmail account name which was created to use your SMTP server'
EMAIL_HOST_PASSWORD = '16 digit password of your SMTP server'

@ameersuhemat -- did hints posted by @nani1531 and @neso solve the issue for you, or you need more assistance?

i follow the below intruction after that my error goes end.and i get email message perfectly.

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_HOST_USER = 'the gmail account name which was created to use your SMTP server' EMAIL_HOST_PASSWORD = '16 digit password of your SMTP server'

after that you do : 1)DisplayUnlockCaptcha https://accounts.google.com/DisplayUnlockCaptcha

NOTE: Please before start your appliction SAVE it AND Reload It . If Any one not solve it please email me on this email : raeeshrayeen98@gmail.com

Glad to hear that it works for you!

My question is - all works perfectly when i fill the form and get a varification link (after doing all other stuff like turning on "less secure app access" and must login through the same google account in web browser) in my browser But what if i deployed my website then others user of my website will fill form then he will definitely get an error on getting verification link because my gmail account which sends email to the people is logged in in my browser not in his. what could be the other things to sort out this problem.

My question is - all works perfectly when i fill the form and get a varification link (after doing all other stuff like turning on "less secure app access" and must login through the same google account in web browser) in my browser But what if i deployed my website then others user of my website will fill form then he will definitely get an error on getting verification link because my gmail account which sends email to the people is logged in in my browser not in his. what could be the other things to sort out this problem.

You're using the the wrong form of authentication. The authentication type that you're using is meant for situations where an web application needs access to a specific user's google account. That is why we have a help page about using app-specific passwords: https://help.pythonanywhere.com/pages/GmailAppSpecificPasswords