[英]Why is my send_mail() command not working in Django?
I put the following in my settings.py file. 我在settings.py文件中添加了以下内容。 The email address there is a test one. 电子邮件地址有一个测试版。 I found the email settings from Webfaction 's site: 我在Webfaction的网站上找到了电子邮件设置:
EMAIL_HOST = 'smtp.webfaction.com'
EMAIL_HOST_USER = 'hekevintran_test'
EMAIL_HOST_PASSWORD = 'testpass'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
This is what my file looks like: 这是我的文件的样子:
from django.core.mail import send_mail
send_mail(subject='subject',
message='message',
from_email='hekevintran_test@webfaction.com',
recipient_list=['recipient@yahoo.com'],
fail_silently=False)
When I run the above it stalls a long time and then gives me this error: 当我运行上面它停止很长时间然后给我这个错误:
SMTPServerDisconnected: Connection unexpectedly closed
What am I doing wrong? 我究竟做错了什么?
I have a Django project on Webfaction right now that is properly sending emails. 我现在有一个关于Webfaction的Django项目正在发送电子邮件。 The only difference between your settings and mine is that I did not specify EMAIL_PORT
or EMAIL_USE_TLS
. 您和我的设置之间的唯一区别是我没有指定EMAIL_PORT
或EMAIL_USE_TLS
。 Try it out without those settings and let Django use the default it has and see if it works. 尝试没有这些设置,让Django使用它的默认值,看看它是否有效。
For reference's sake, the default settings are: 出于参考考虑, 默认设置为:
EMAIL_PORT = 25
EMAIL_USE_TLS = False
I had this problem with my hosted account at asmallorange.com. 我在asmallorange.com上的托管帐户遇到了这个问题。 There, it was a firewall problem. 在那里,这是一个防火墙问题。 I would suggest contacting support and ensuring port 465 can get through the firewall. 我建议联系支持并确保端口465可以通过防火墙。
I had this problem too. 我也有这个问题。 I deleted EMAIL_PORT and set EMAIL_USE_TLS = True. 我删除了EMAIL_PORT并设置了EMAIL_USE_TLS = True。 Now it is work. 现在是工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.