Django - Gmail - SMTPAuthenticationError

  • Posted December 10, 2013

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;


Anyone know why I’m getting the exception, when running the code in a VPS. Note : running Gunicorn & Nginx

Any help or advice appreciated.


This comment has been deleted

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

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Going to <br>and then retrying the operation, worked a treat! <br> <br>Thank You Pablo.

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

I was having a similar problem and i solve it changing the order of the settings. <br>It worked exactly like this <br> <br>EMAIL_USE_TLS = True <br>EMAIL_HOST = ‘’ <br>EMAIL_HOST_USER = “” <br>EMAIL_HOST_PASSWORD = “xxxxxxxx” <br>EMAIL_PORT = 587 <br> <br>You can try it easy with the django shell: <br> <br>>>> from django.core.mail import send_mail <br>>>> send_mail(‘test email’, ‘hello world’, ‘’, [‘’]) <br> <br>hope it helps

Make sure the password is correct. If it is, check out the last 2 answers in <a href=“”>Net::SMTPAuthenticationError when sending email from Rails app (on staging environment) | Stack Overflow</a> or this GitHub issue: <a href=“”>Error: Net::SMTPAuthenticationError in RegistrationsController#create when signing up</a>.

No firewall, currently; just a minimal install to try things out. <br> <br>Internal Server Error: /contact/ <br>Traceback (most recent call last): <br> File “/usr/local/lib/python2.7/dist-packages/django/core/handlers/”, line 114, in get_response <br> response = wrapped_callback(request, *callback_args, **callback_kwargs) <br> File “/usr/local/lib/python2.7/dist-packages/django/views/generic/”, line 69, in view <br> return self.dispatch(request, *args, **kwargs) <br> File “/usr/local/lib/python2.7/dist-packages/django/views/generic/”, line 87, in dispatch <br> return handler(request, *args, **kwargs) <br> File “/opt/officeowlsproject/officeowls/source/contact/”, line 39, in post <br> form.cleaned_data[‘message’]) <br> File “/opt/officeowlsproject/officeowls/source/contact/”, line 49, in send_notification_mail <br> send_mail(subject, message, settings.EMAIL_HOST_USER, [settings.EMAIL_HOST_USER]) <br> File “/usr/local/lib/python2.7/dist-packages/django/core/mail/”, line 50, in send_mail <br> connection=connection).send() <br> File “/usr/local/lib/python2.7/dist-packages/django/core/mail/”, line 255, in send <br> return self.get_connection(fail_silently).send_messages([self]) <br> File “/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/”, line 88, in send_messages <br> new_conn_created = <br> File “/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/”, line 55, in open <br> self.connection.login(self.username, self.password) <br> File “/usr/lib/python2.7/”, line 613, in login <br> raise SMTPAuthenticationError(code, resp) <br>SMTPAuthenticationError: (534, ‘5.7.14 <\n5.7.14 C3OFcvHRPuxJl5KXY2WfGco2S4KGxD0b9bkAeTsStDqcjfaXNfQBUyAX1mYliPsclp_QwW\n5.7.14 B7j59cqV2GG_2lwVDsF0mHphSw-HDNyQlb-9-bBIOz7PN4m3izZ0yOygEEcNqZflbwPh30\n5.7.14 lu2tKiwq-jJADcCA-MWU-7S4aX3662QyE37pirFW0Fw2yrVmU8c1WBXgW4DhMDFaMzksnV\n5.7.14 f_dWQag> Please log in via your web browser and then try again.\n5.7.14 Learn more at\n5.7.14 54 c1sm9978624qad.1 - gsmtp’)

What do the error logs show? Do you have a firewall in place, by chance?