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;
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.
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!
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
Going to https://accounts.google.com/DisplayUnlockCaptcha <br>and then retrying the operation, worked a treat! <br> <br>Thank You Pablo.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.