我想從我的服務器發送電子郵件。我正嘗試使用我已有的hotmail帳戶發送。通過python中的hotmail發送電子郵件
user = "[email protected]"
passwd = "xxxxxxxxx"
from_addr = "[email protected]"
to_addr = "[email protected]"
smtp_srv = "smtp.live.com"
subject = "Home Server Uptime"
message = "The server has been online for: %s" %(uptime)
smtp = smtplib.SMTP(smtp_srv,587)
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login(user, passwd)
smtp.sendmail(from_addr, to_addr, message)
smtp.quit()
我得到這個錯誤:
Traceback (most recent call last):
File "sendemail.py", line 23, in <module>
smtp.starttls()
File "/usr/lib/python2.7/smtplib.py", line 636, in starttls
(resp, reply) = self.docmd("STARTTLS")
File "/usr/lib/python2.7/smtplib.py", line 385, in docmd
return self.getreply()
File "/usr/lib/python2.7/smtplib.py", line 358, in getreply
+ str(e))
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [Errno 104] Connection reset by peer
我不知道如何解決這個。
這裏是set_debuglevel的輸出(1)彌敦道建議:
send: 'ehlo [127.0.1.1]\r\n'
reply: '250-BLU0-SMTP190.blu0.hotmail.com Hello [my-ip-address]\r\n'
reply: '250-TURN\r\n'
reply: '250-SIZE 41943040\r\n'
reply: '250-ETRN\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-DSN\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-8bitmime\r\n'
reply: '250-BINARYMIME\r\n'
reply: '250-CHUNKING\r\n'
reply: '250-VRFY\r\n'
reply: '250-TLS\r\n'
reply: '250-STARTTLS\r\n'
reply: '250 OK\r\n'
reply: retcode (250); Msg: BLU0-SMTP190.blu0.hotmail.com Hello [my-ip-address]
TURN
SIZE 41943040
ETRN
PIPELINING
DSN
ENHANCEDSTATUSCODES
8bitmime
BINARYMIME
CHUNKING
VRFY
TLS
STARTTLS
OK
send: 'STARTTLS\r\n'
Traceback (most recent call last):
File "sendemail.py", line 24, in <module>
smtp.starttls()
File "/usr/lib/python2.7/smtplib.py", line 636, in starttls
(resp, reply) = self.docmd("STARTTLS")
File "/usr/lib/python2.7/smtplib.py", line 385, in docmd
return self.getreply()
File "/usr/lib/python2.7/smtplib.py", line 358, in getreply
+ str(e))
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [Errno 104] Connection reset by peer
你試過'smtp.set_debuglevel(1)'?你可能會得到更多有用的輸出。 –
在主文章中粘貼了set_debuglevel(1)的輸出 – koogee