2015-11-06 21 views
0
import smtplib 
fromaddr = "Insert your email here" 
toaddr = ["insert receivers adress here"] 


message = """From: fromname <[email protected]> 
To: To Person <[email protected]> 
Subject: Insert Subject here""" 

emails_done = 1 
server = smtplib.SMTP('smtp.gmail.com', 587) 
server.starttls() 
server.login(fromaddr, "InsertPassword") 
for i in range(int(raw_input('how many emails?'))): 
    server.sendmail(fromaddr, toaddr,message) 
    print(emails_done) 
    emails_done = emails_done + 1 
server.quit() 

我试着去垃圾邮件我的朋友有100封邮件作为一个恶作剧,但我有代码的一些问题,我得到了很多不同的错误,如:Python的垃圾邮件发送错误

Traceback (most recent call last): 
    File "/Volumes/Data/Users/106299/Desktop/EMAIL .py", line 45, in <module> 
    server.sendmail(fromaddr, toaddr,message) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 723, in sendmail 
    self.rset() 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 462, in rset 
    return self.docmd("rset") 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 387, in docmd 
    return self.getreply() 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 360, in getreply 
    + str(e)) 
SMTPServerDisconnected: Connection unexpectedly closed: [Errno 54] Connection reset by peer 

Ive收到了78封电子邮件,它总是在那里结束。有时也把它发送一个大电子邮件线程/变化,而不是100个独立emails.Here是另一个

Traceback (most recent call last): 
    File "/Volumes/Data/Users/106299/Desktop/EMAIL .py", line 45, in <module> 
    server.sendmail(fromaddr, toaddr,message) 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 723, in sendmail 
    self.rset() 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 462, in rset 
    return self.docmd("rset") 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 387, in docmd 
    return self.getreply() 
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 363, in getreply 
    raise SMTPServerDisconnected("Connection unexpectedly closed") 
SMTPServerDisconnected: Connection unexpectedly closed 

我在MacBook Air上
运行的Python 2.7.8任何帮助,将不胜感激:>
PS抱歉废话格式化,第一篇文章。

回答

0

一种可能性是gmail拒绝每秒一定数量的请求。
试着把server.set_debuglevel(1)放在server.starttls()之后,这会让你看到函数调用的调试细节。这些信息可能会引导您找到解决方案。

相关问题