Django - Gmail - SMTPAuthenticationError

December 10, 2013 30.3k views
I have a Django project, in which I'm attempting to send an email using my gmail account. Note this works fine on my dev machine. Code : from django.core.mail import send_mail ... send_mail(subject, message, settings.EMAIL_HOST_USER, [settings.EMAIL_HOST_USER]) Settings : EMAIL_HOST = '' EMAIL_HOST_USER = '' EMAIL_HOST_PASSWORD = 'xxxxxxxxxxxxx' EMAIL_PORT = 587 # Tried 465 as mentioned in; # EMAIL_USE_TLS = True Anyone know why I'm getting the exception, when running the code in a VPS. Note : running Gunicorn & Nginx Any help or advice appreciated.
6 Answers
Going to
and then retrying the operation, worked a treat!

Thank You Pablo.
I was having a similar problem and i solve it changing the order of the settings.
It worked exactly like this


You can try it easy with the django shell:

>>> from django.core.mail import send_mail
>>> send_mail('test email', 'hello world', '', [''])

hope it helps
  • I tried everything in the books to get my email to work. Your solution ended up working for me! At first, I had USE_TLS at the bottom. Moving it to the top, like yours, fixed it.

What do the error logs show? Do you have a firewall in place, by chance?
No firewall, currently; just a minimal install to try things out.

Internal Server Error: /contact/
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/", line 114, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/", line 69, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/", line 87, in dispatch
return handler(request, *args, **kwargs)
File "/opt/officeowlsproject/officeowls/source/contact/", line 39, in post
File "/opt/officeowlsproject/officeowls/source/contact/", line 49, in send_notification_mail
send_mail(subject, message, settings.EMAIL_HOST_USER, [settings.EMAIL_HOST_USER])
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/", line 50, in send_mail
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/", line 255, in send
return self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/", line 88, in send_messages
new_conn_created =
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/", line 55, in open
self.connection.login(self.username, self.password)
File "/usr/lib/python2.7/", line 613, in login
raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (534, '5.7.14 Please log in via your web browser and then try again.\n5.7.14 Learn more at\n5.7.14 54 c1sm9978624qad.1 - gsmtp')

It is because Google blocks sign-in attempts from apps which do not use modern security standards (mentioned on their support page). You can however, turn on/off this safety feature by going to the link below:

Go to this link and select Turn On

Moreover google block an ip when you try to send a email since a unusual location, so, you can unblock in the next link

and clicked in

More info…smtp mail

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!