进行身份验证时,通过python发送来自Gmail smtp的邮件失败

时间:2017-12-16 16:00:30

标签: python gmail

我尝试从gmail smtp发送邮件,但是我使用的很多lib都有同样的问题,所以我自己编写代码,但仍然遇到同样的问题。

邮件地址和密码正确无误,并设置“允许不够安全的应用程序:已启用 “,但登录时仍然失败。

In [3]: import smtplib

In [4]: sender = "xxxx@gmail.com"

In [5]: receiver = ["a@m.com", "b@m.com"]

In [6]: message = "Some say, the hole that you have is not what you think about. "

In [7]: session = smtplib.SMTP('smtp.gmail.com',587)

In [8]: session.ehlo()
Out[8]:
(250,
 'smtp.gmail.com at your service, [52.69.222.223]\nSIZE 35882577\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES\nPIPELINING\nCHUNKING\nSMTPUTF8')

In [9]: session.starttls()
Out[9]: (220, '2.0.0 Ready to start TLS')

In [10]: session.ehlo()
Out[10]:
(250,
 'smtp.gmail.com at your service, [52.69.222.223]\nSIZE 35882577\n8BITMIME\nAUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH\nENHANCEDSTATUSCODES\nPIPELINING\nCHUNKING\nSMTPUTF8')

In [11]: session.login(sender,'xxxxxxxxxx')
---------------------------------------------------------------------------
SMTPAuthenticationError                   Traceback (most recent call last)
<ipython-input-12-d9e3f09f8956> in <module>()
----> 1 session.login(sender,'RVt-p2o-DNH-KUx')

/usr/lib/python2.7/smtplib.pyc in login(self, user, password)
    620             # 235 == 'Authentication successful'
    621             # 503 == 'Error: already authenticated'
--> 622             raise SMTPAuthenticationError(code, resp)
    623         return (code, resp)
    624

SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsM\n5.7.14 0ac0_dvD0Y_cg29gAxTuOXREOWblLYFSrQlrVnGUA98X18_Bht8wEh-uL_nhqDReDOqF8Z\n5.7.14 Ll39ZurQoK631iZ9Q_cbkAAHqRZBpWMfGnZUMUONSycVww2_YydzB0vQUGGb3lrboeriGh\n5.7.14 gHVI6Vw5SUYyUDCJyfV3Jav_oJFgbLvyK2a0UwllJvt8gQqvy7JhpFIQoybHlpuG5ZLu23\n5.7.14 JNo4Ru7q6vU3aaRfWKl7YoNnRRVHA> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 s14sm19463632pfe.36 - gsmtp')

0 个答案:

没有答案