发送电子邮件时出错:引发SMTPAuthenticationError(代码,分别) [英] Error sending email: raise SMTPAuthenticationError(code, resp)
本文介绍了发送电子邮件时出错:引发SMTPAuthenticationError(代码,分别)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用smtp模块发送电子邮件,但是我遇到错误:
Im trying to send emails with smtp module, but Im having an error:
File "/usr/lib/python2.7/smtplib.py", in login
raise SMTPAuthenticationError(code, resp) smtplib.SMTPAuthenticationError: (534, '5.7.14)...
有人已经发生此错误?您知道如何解决吗?
Someone already had this error? Do you know how to fix?
代码:
def sendNotification():
recepients_list = "emailsmtplibtest@gmail.com"
subject = 'Subject'
message = "Message"
sendemail(recepients_list,subject,message)
def sendemail(to_addr_list, subject, message):
username = 'emailsmtplibtest@gmail.com'
password = 'passtest'
from_addr = 'emailsmtplibtest@gmail.com'
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(username,password)
newmessage = '\r\n'.join([
'To: %s' %recepient_list,
'From: %s' % from_addr,
'Subject: %s' %subject,
'',
message
])
try:
server.sendemail(from_addr, to_addr_list,newmessage)
print 'notification sent'
except:
print 'error sending notification'
server.quit()
sendNotification()
推荐答案
转到Google的帐户安全设置:
www.google.com/settings/security
Go to Google's Account Security Settings: www.google.com/settings/security
找到访问安全性较低的应用程序字段。
将其设置为允许。
Find the field "Access for less secure apps". Set it to "Allowed".
重试脚本,更改 server.sendemail()
到 server.sendmail()
这篇关于发送电子邮件时出错:引发SMTPAuthenticationError(代码,分别)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文