可能重复:
使用 python 发送电子邮件
我正在尝试使用 python 发送电子邮件,但是当我运行脚本时需要一两分钟,然后我收到此错误:
Traceback (most recent call last):
File "./emailer", line 19, in <module>
server = smtplib.SMTP(SERVER)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 273, in _get_socket
return socket.create_connection((port, host), timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/socket.py", line 512, in create_connection
raise error, msg
socket.error: [Errno 60] Operation timed out
这是脚本:
#!/usr/bin/env python
import smtplib
SERVER = 'addisonbean.com'
FROM = 'myemail@gmail.com'
TO = ['myemail@gmail.com']
SUBJECT = 'Hello!'
message = """\
Bla
Bla Bla
Bla Bla Bla
Bla Bla Bla Bla
"""
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()
我还尝试将我的站点 IP 地址作为服务器,但它做了同样的事情。
有人可以告诉我为什么会这样以及如何解决这个问题吗?谢谢!