I am trying to send an email using Django send_email, smtp and gmail. However, the code returns SMTPConnectError (-1, ' ')
My settings.py file: ALLOWED_HOSTS = [] DEFAULT_FROM_EMAIL = 'mygmailid' SERVER_EMAIL = 'mygmailid' EMAIL_USE_TLS = True EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = 'mygmailid' EMAIL_HOST_PASSWORD = 'myPassword' EMAIL_PORT = 587 My views.py file: from django.http import HttpResponse from django.core.mail import send_mail from smtplib import SMTPConnectError #rest of the code in between .... try: send_mail('testmail', 'test content', settings.EMAIL_HOST_USER, ['arkaghosh...@gmail.com', fail_silently=False]) except SMTPConnectError as e: return HttpResponse(e) The traceback: Traceback (most recent call last):File "<console>", line 1, in <module>File "C:\Python34\lib\site-packages\django-1.8.2- py3.4.egg\django\core\mail\__ init__.py", line 62, in send_mailreturn mail.send()File "C:\Python34\lib\site-packages\django-1.8.2- py3.4.egg\django\core\mail\me ssage.py", line 303, in sendreturn self.get_connection(fail_silently).send_messages([self])File "C:\Python34\lib\site-packages\django-1.8.2-py3.4.egg\django\core\mail\ba ckends\smtp.py", line 100, in send_messages new_conn_created = self.open()File "C:\Python34\lib\site-packages\django-1.8.2-py3.4.egg\django\core\mail\ba ckends\smtp.py", line 58, in open self.connection = connection_class(self.host, self.port, **connection_params)File "C:\Python34\lib\smtplib.py", line 244, in __init__raise SMTPConnectError(code, msg) smtplib.SMTPConnectError: (-1, '') When I change the EMAIL_BACKEND to: EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' it works fine. Also, it doesn't show the error when I use dummy backend. I have tried using SSL instead of TLS, unlocked captcha, allowed less secure apps in gmail, turned off firewall and also tried other stackoverflow posts related to sending email via django but nothing worked. I don't know what the error is. Please help me. Thanks in advance. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/afea10d8-96b0-43bd-a4a5-e65b18956be7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.