从行开始的所有行都返回错误Errno 10060或错误Errno 10061:
import smtplib
server = smtplib.SMTP('smtp.gmail.com:465')
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer = smtplib.SMTP("smtp.gmail.com", 465)
mailServer = smtplib.SMTP("smtp.mail.ru", 25)
mailServer = smtplib.SMTP("smtp.mail.ru", 2525)
你可以帮忙吗?我必须遗漏一些微不足道的错误消息:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\lib\smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python27\lib\smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\lib\smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
答案 0 :(得分:2)
使用smtplib.SMTP_SSL()
进行TLS连接。
答案 1 :(得分:2)
以下所有命令都没有错;我的问题确实是由知识产权限制造成的。谢谢你的所有答案。
答案 2 :(得分:1)
或使用server = smtplib.SMTP('smtp.gmail.com:25')
进行正常连接
如果您想要从端口25输入,只需添加
即可server.starttls()
在第一行之后。
ps:由于端口25是默认值,因此以下内容是等效的:
server = smtplib.SMTP('smtp.gmail.com')
server.starttls()