我的settings.py文件:
ALLOWED_HOSTS = []DEFAulT_FROM_EMAIL = 'mygmailID'SERVER_EMAIL = 'mygmailID'EMAIL_USE_TLS = TrueEMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'EMAIL_HOST = 'smtp.gmail.com'EMAIL_HOST_USER = 'mygmailID'EMAIL_HOST_PASSWORD = 'myPassword'EMAIL_PORT = 587
我的vIEws.py文件:
from django.http import httpResponsefrom django.core.mail import send_mailfrom smtplib import SMTPConnectError#rest of the code in between....try: send_mail('testmail','test content',settings.EMAIL_HOST_USER,['arkaghosh024@gmail.com',fail_silently=False])except SMTPConnectError as e: return httpResponse(e)
追溯:
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\message.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\backends\smtp.py",line 100,in send_messagesnew_conn_created = self.open()file "C:\python34\lib\site-packages\django-1.8.2-py3.4.egg\django\core\mail\backends\smtp.py",line 58,in openself.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,b")
当我将EMAIL_BACKEND更改为:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
它工作正常.此外,当我使用虚拟后端时,它不会显示错误.
我尝试过使用SSL代替TLS,允许gmail中安全性较低的应用程序,关闭防火墙,还尝试了其他与通过django发送电子邮件相关的stackoverflow帖子,但没有任何效果.我不知道错误是什么.请帮我.提前致谢.
解决方法 Gmail帐户需要这样:EMAIL_HOST = 'smtp.gmail.com'EMAIL_HOST_USER = 'your-username@gmail.com'EMAIL_HOST_PASSWORD = 'your-password'EMAIL_PORT = 587EMAIL_USE_TLS = True
>然后测试其作品:
python manage.py shell
from django.core.mail import send_mailsend_mail('testemail','hi','Youremail@email.com',['Emailtest@email.com'])
如果您没有使用Gmail帐户但仍然遇到问题,那么只需尝试将EMAIL_HOST_USER和EMAIL_HOST_PASSWORD添加到您拥有的内容中即可.如果您仍有问题,可能是您的网络阻止了您. *** 作系统或路由器上的防火墙.
总结以上是内存溢出为你收集整理的python – Django send_mail返回SMTPConnectError全部内容,希望文章能够帮你解决python – Django send_mail返回SMTPConnectError所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)