【发布时间】:2017-04-26 04:55:54
【问题描述】:
我正在尝试使用 Python 的 smtplib 模块发送电子邮件,但我一直收到TimeoutError。
import smtplib
def send():
try:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(email, password) # Email and password are already defined
print('Enter recipient: ')
recipient = input()
print('Enter subject:')
subject = input() + '\n'
print('Enter body:')
body = input()
server.sendmail(email, recipient, body)
server.quit()
except TimeoutError as e:
print (str(e))
此代码收到:
[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
【问题讨论】:
-
可能是连接问题或防火墙?