Question

Django - Gmail - SMTPAuthenticationError

  • Posted on December 10, 2013
  • jstoor21Asked by jstoor21

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 = ‘smtp.gmail.com’ EMAIL_HOST_USER = ‘xxxxx@gmail.com’ EMAIL_HOST_PASSWORD = ‘xxxxxxxxxxxxx’ EMAIL_PORT = 587 # Tried 465 as mentioned in;

https://www.digitalocean.com/community/articles/how-to-use-google-s-smtp-server

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.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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 https://accounts.google.com/DisplayUnlockCaptcha <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

https://www.google.com/settings/security/lesssecureapps

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

https://support.google.com/accounts/answer/6009563

and clicked in

accounts.google.com/DisplayUnlockCaptcha

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 = ‘smtp.gmail.com’ <br>EMAIL_HOST_USER = “xxxx@gmail.com” <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’, ‘xxxx@gmail.com’, [‘xxx@yyyy.com’]) <br> <br>hope it helps