What is causing SMTPAuthenticationError

I just deployed my application to an ubuntu server. I have ssl, so I made the respective modifications in my settings.py, it looks like this:

EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_SSL = True

I believe this is the Right configuration but when a email is sent I get something like:

Traceback (most recent call last):
  File "/home/admin/Mefid/TransversalScripts/comunication.py", line 122, 
in send_email
    fail_silently=False, html_message=html_message)
  File "/home/admin/Mefid/venv2/lib/python3.7/site- 
packages/django/core/mail/__init__.py", line 60, in send_mail
return mail.send()
File "/home/admin/Mefid/venv2/lib/python3.7/site- 
packages/django/core/mail/message.py", line 291, in send
return self.get_connection(fail_silently).send_messages([self])
File "/home/admin/Mefid/venv2/lib/python3.7/site- packages/django/core/mail/backends/smtp.py", line 103, in send_messages
new_conn_created = self.open()
  File "/home/admin/Mefid/venv2/lib/python3.7/site-packages/django_smtp_ssl.py", line 14, in open
self.connection.login(self.username, self.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=AKgnsbvc\n5.7.14 YlL_uB0GK_TLI557gRMyVYqHRr9iVrfj5mJ3jaEuyHjSmmevxT5-8ocIMMRh0BVOPqnrCR\n5.7.14 prX-jJCduiyPcF2RrYAWJkg4A5jUboKUMLzBEyz72VWQLPYiOKxFcZ5SBvrICb> Please\n5.7.14 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 i11sm7651758oia.9 - gsmtp')

'''

I followed a guide here https://github.com/bancek/django-smtp-ssl is there anything else I should be aware of? Thanks for your help.

Upvotes: 0

Views: 294

Answers (1)

pranjal0819
pranjal0819

Reputation: 321

Make sure you have turned on Less secure app access in Google account

Go to your Google Account settings, find Security -> Account permissions -> Access for less secure apps, enable this option.

About this option: https://support.google.com/accounts/answer/6010255

Upvotes: 1

Related Questions