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.
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.
Going to https://accounts.google.com/DisplayUnlockCaptcha <br>and then retrying the operation, worked a treat! <br> <br>Thank You Pablo.
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
Make sure the password is correct. If it is, check out the last 2 answers in <a href=“http://stackoverflow.com/questions/18124878/netsmtpauthenticationerror-when-sending-email-from-rails-app-on-staging-envir”>Net::SMTPAuthenticationError when sending email from Rails app (on staging environment) | Stack Overflow</a> or this GitHub issue: <a href=“https://github.com/Coursemology/coursemology.org/issues/15”>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/base.py”, 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/base.py”, line 69, in view <br> return self.dispatch(request, *args, **kwargs) <br> File “/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py”, line 87, in dispatch <br> return handler(request, *args, **kwargs) <br> File “/opt/officeowlsproject/officeowls/source/contact/views.py”, line 39, in post <br> form.cleaned_data[‘message’]) <br> File “/opt/officeowlsproject/officeowls/source/contact/views.py”, 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/init.py”, line 50, in send_mail <br> connection=connection).send() <br> File “/usr/local/lib/python2.7/dist-packages/django/core/mail/message.py”, 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/smtp.py”, line 88, in send_messages <br> new_conn_created = self.open() <br> File “/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py”, line 55, in open <br> self.connection.login(self.username, self.password) <br> File “/usr/lib/python2.7/smtplib.py”, line 613, in login <br> raise SMTPAuthenticationError(code, resp) <br>SMTPAuthenticationError: (534, ‘5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbsqI\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 https://support.google.com/mail/bin/answer.py?answer=787\n5.7.14 54 c1sm9978624qad.1 - gsmtp’)
What do the error logs show? Do you have a firewall in place, by chance?
This comment has been deleted