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