Possible Duplicate:
Send email with python试图与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 = '[email protected]'
TO = ['[email protected]']
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地址作为服务器,但是做了同样的事情。
有人能告诉我为什么这样做,以及如何解决这个问题?谢谢!
SMTP服务器不需要任何身份验证吗?因为他们通常会做 – BorrajaX 2012-08-01 23:44:34
您需要使用实际的邮件服务器作为服务器地址。你不能放入任何随机的主机名。 – geoffspear 2012-08-01 23:46:21