Use*_*erX 5 python email smtplib
我试图用smtp模块发送电子邮件,但我有一个错误:
File "/usr/lib/python2.7/smtplib.py", in login
raise SMTPAuthenticationError(code, resp) smtplib.SMTPAuthenticationError: (534, '5.7.14)...
Run Code Online (Sandbox Code Playgroud)
有人已经有这个错误吗?你知道怎么解决吗?
代码:
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()
Run Code Online (Sandbox Code Playgroud)
转到Google的帐户安全设置: www.google.com/settings/security
找到"访问不太安全的应用程序"字段.将其设置为"允许".
再次尝试您的脚本,更改server.sendemail()为server.sendmail()