我正在尝试使用smtplib
编写python auto-mailer
。我已经让它运行了,但我一直在执行我的except语句
代码看起来像这样
sender = ['..........@gmail.com']
receivers = ['.......@gmail.com']
subject = "does this work?"
message = "this is a cool email"
try:
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.sendmail(sender, receivers, message)
print("Successfully sent email")
server.quit()
except smtplib.SMTPException:
print("Error: unable to send email")
感谢您的帮助
编辑:堆栈跟踪如下
Traceback (most recent call last):
File "C:/Users/......py", line 38, in <module>
email_protocol()
File "C:/Users/....py", line 33, in email_protocol
server.sendmail(sender, receivers, message)
File "C:\Users\...\lib\smtplib.py", line 867, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError c33sm2599297qtb.76 - gsmtp', ['....@gmail.com'])
Process finished with exit code 1
这个错误是不言自明的。您需要提供身份验证
把这个放在
server.starttls()
后面有关详细信息,请参阅https://docs.python.org/2/library/smtplib.html#smtplib.SMTP.login
相关问题 更多 >
编程相关推荐