使用 gmail 和 python 发送邮件时出现 SMTPAuthenticationError [英] SMTPAuthenticationError when sending mail using gmail and python

查看:78
本文介绍了使用 gmail 和 python 发送邮件时出现 SMTPAuthenticationError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 gmail 发送邮件时,发生了 python 错误,此类型的问题已经出现在此站点中,但对我没有帮助

when i try to send mail using gmail and python error occurred this type of question are already in this site but doesn't help to me

gmail_user = "me@gmail.com"
gmail_pwd = "password"
TO = 'friend@gmail.com'
SUBJECT = "Testing sending using gmail"
TEXT = "Testing sending mail using gmail servers"
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
BODY = '\r\n'.join(['To: %s' % TO,
        'From: %s' % gmail_user,
        'Subject: %s' % SUBJECT,
        '', TEXT])

server.sendmail(gmail_user, [TO], BODY)
print ('email sent')

错误:

    server.login(gmail_user, gmail_pwd)
    File "/usr/lib/python3.4/smtplib.py", line 639, in login
   raise SMTPAuthenticationError(code, resp)
   smtplib.SMTPAuthenticationError: (534, b'5.7.14   
   <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbtl1\n5.7.14       Li2yir27TqbRfvc02CzPqZoCqope_OQbulDzFqL-msIfsxObCTQ7TpWnbxIoAaQoPuL9ge\n5.7.14 BUgbiOqhTEPqJfb02d_L6rrdduHSxv26s_Ztg_JYYavkrqgs85IT1xZYwtbWIRE8OIvQKf\n5.7.14 xxtT7ENlZTS0Xyqnc1u4_MOrBVW8pgyNyeEgKKnKNyxce76JrsdnE1JgSQzr3pr47bL-kC\n5.7.14 XifnWXg> Please log in via your web browser and then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 fl15sm17237099pdb.92 - gsmtp')    

推荐答案

您的代码看起来正确.尝试通过浏览器登录,如果您能够访问您的帐户,请返回并再次尝试您的代码.只需确保您输入的用户名和密码正确

Your code looks correct. Try logging in through your browser and if you are able to access your account come back and try your code again. Just make sure that you have typed your username and password correct

编辑:Google 会阻止来自不使用现代安全标准的应用的登录尝试(在其支持页面).但是,您可以通过以下链接打开/关闭此安全功能:

EDIT: Google blocks sign-in attempts from apps which do not use modern security standards (mentioned on their support page). You can however, turn on/off this safety feature by going to the link below:

转到此链接并选择开启
https://www.google.com/settings/security/lesssecureapps

这篇关于使用 gmail 和 python 发送邮件时出现 SMTPAuthenticationError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆