如何使用 Django 电子邮件修复 [WinError 10061]?
(目标机器主动拒绝,无法连接)
我正在使用 Django 发送电子邮件。我显然遇到了一个常见的网络错误,但我读过的任何答案都没有解决。我相信我的插座有问题,
当我发送电子邮件时,出现以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\site-
packages\django\core\mail\message.py", line 291, in send
return self.get_connection(fail_silently).send_messages([self])
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\site-
packages\django\core\mail\backends\smtp.py", line 103, in send_messages
new_conn_created = self.open()
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\site-
packages\django\core\mail\backends\smtp.py", line 63, in open
self.connection = self.connection_class(self.host, self.port,
**connection_params)
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\smtplib.py", line 251,
in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\smtplib.py", line 336,
in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\smtplib.py", line 307,
in _get_socket
self.source_address)
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\socket.py", line 727,
in create_connection
raise err
File "C:\Users\Jaime\Miniconda3\envs\mydjango\lib\socket.py", line 716,
in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made
because
the target machine actively refused it
这是我尝试过的:
1)
import socket
socket.getaddrinfo('hotmail-com.olc.protection.outlook.com', 80)
socket.getaddrinfo('smtp.hotmail.com', 8000)
socket.getaddrinfo('smtp.hotmail.com', 587)
2)
关闭防火墙/防病毒
3)
在 python shell 和 Django 应用程序中运行代码
4)
我从 nslookup MX 查询中获得了 smtp 服务器
我在 python shell 中运行这个测试代码:
from django.conf import settings
from django.core.mail import EmailMessage
settings.configure()
from django.core.mail import send_mail
import socket
socket.getaddrinfo('hotmail-com.olc.protection.outlook.com', 80)
预期结果
现在我想从 localhost Django 应用程序发送电子邮件。将来我会将代码上传到 pythonanywhere.com 服务器。
一只名叫tom的猫
侃侃无极
相关分类