2012-07-31 103 views
3

發送電子郵件,我嘗試使用下面的代碼發送電子郵件:錯誤而從Hotmail SMTP的Python

s = smtplib.SMTP("smtp.live.com",587, timeout=120) 
    s.ehlo() 
    s.starttls() 
    s.ehlo() 
    s.login(user, pass) 
msg["To"] = string.joinfields(bundle, ", ") 
    s.sendmail(usuario, bundle, msg) 

但是我得到的錯誤如下:

File "C:\Python27\lib\smtplib.py", line 242, in __init__ 
    (code, msg) = self.connect(host, port) 
    File "C:\Python27\lib\smtplib.py", line 302, in connect 
    self.sock = self._get_socket(host, port, self.timeout) 
    File "C:\Python27\lib\smtplib.py", line 277, in _get_socket 
    return socket.create_connection((port, host), timeout) 
    File "C:\Python27\lib\socket.py", line 571, in create_connection 
    raise err 
error: [Errno 10060] A connection attempt failed because the connected party did 
not properly respond after a period of time, or established connection failed b 
ecause connected host has failed to respond 

我做錯了嗎?

回答

1

沒什麼,我想。可能你是在防火牆後面,或者Hotmail在糟糕的一天。從命令提示符下,嘗試telnet smtp.live.com 587。如果您未收到回覆,則說明您的連接存在問題。

這裏的結果我得到:

$ telnet smtp.live.com 587 
Trying 65.55.96.11... 
Connected to smtp.hot.glbdns.microsoft.com. 
Escape character is '^]'. 
220 BLU0-SMTP406.phx.gbl Microsoft ESMTP MAIL Service, Version: 6.0.3790.4675 ready at Mon, 30 Jul 2012 19:37:46 -0700 
+0

真的,這是連接問題。它在另一臺機器上工作。 – dextervip 2012-07-31 02:45:56

+0

這是一個簡單的解決方案,然後:) – Max 2012-07-31 02:48:47