-1
以下是我的脚本来连接到SMTP服务器和发送邮件。无法使用python脚本连接到SMTP服务器
from smtplib import SMTP
import datetime
debuglevel = 0
smtp = SMTP()
smtp.set_debuglevel(debuglevel)
smtp.connect('smtp.gmail.com', 26)
smtp.login('[email protected]', 'Pa***wd')
from_addr = "Ashwin<[email protected]>"
to_addr = "[email protected]"
subj = "hello"
date = datetime.datetime.now().strftime("%d/%m/%Y %H:%M")
message_text = "Hello\nThis is a mail from your server\n\nBye\n"
msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s"%(from_addr, to_addr, subj, date, message_text)
smtp.sendmail(from_addr, to_addr, msg)
smtp.quit()
但它引发以下错误: -
Traceback (most recent call last):
File "C:\Python33\Bidhoo.py", line 15, in <module>
smtp.connect('smtp.gmail.com', 26)
File "C:\Python33\lib\smtplib.py", line 317, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python33\lib\smtplib.py", line 288, in _get_socket
self.source_address)
File "C:\Python33\lib\socket.py", line 424, in create_connection
raise err
File "C:\Python33\lib\socket.py", line 415, in create_connection
sock.connect(sa)
TimeoutError: [WinError 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
请帮我找到这个错误的根源。也可以有人共享备用代码连接到SMTP ..
欢迎来到Stack Overflow!为了更好地解答您的问题,请阅读并牢记[如何问](http://stackoverflow.com/questions/how-to-ask)文章。 –