我知道有20个类似的问题,但我已经尝试了一天以上来让Django与电子邮件配合工作。
当我尝试发送电子邮件时,出现了这个错误:[Errno 111] Connection refused
。
以下是我在视图中创建并尝试发送电子邮件的位置:
try:
msg = EmailMessage(subject, message, from_email, [receiver])
msg.content_subtype = "html"
msg.send()
我的设置文件如下:
EMAIL_HOST = "localhost"
DEFAULT_FROM_EMAIL = "myemail@gmail.com"
EMAIL_PORT = 25
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
我尝试使用命令 python -m smtpd -n -c DebuggingServer localhost:1025
进行测试发送并且成功了,但是在实际操作中却没有成功。当我在 shell 中尝试发送邮件时,出现了以下回溯信息:
>>> from django.core.mail import send_mail
>>> send_mail('Test', 'Test', 'myemail@gmail.com', ['myemail@gmail.com'])
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/django/core/mail/__init__.py", line 61, in send_mail
connection=connection).send()
File "/usr/local/lib/python2.6/dist-packages/django/core/mail/message.py", line 251, in send
return self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python2.6/dist-packages/django/core/mail/backends/smtp.py", line 79, in send_messages
new_conn_created = self.open()
File "/usr/local/lib/python2.6/dist-packages/django/core/mail/backends/smtp.py", line 42, in open
local_hostname=DNS_NAME.get_fqdn())
File "/usr/lib/python2.6/smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.6/smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.6/smtplib.py", line 273, in _get_socket
return socket.create_connection((port, host), timeout)
File "/usr/lib/python2.6/socket.py", line 561, in create_connection
raise error, msg
error: [Errno 111] Connection refused
我似乎在这方面毫无进展。非常感谢您的任何帮助或建议。谢谢
另外,如果您还有其他想看到的内容,请留言。