Gmail SMTP身份验证始终失败

时间:2018-10-09 12:52:09

标签: python authentication go smtp gmail

我在python 3中创建了此软件

import smtplib
TO = 'anywhere@mail.com'
SUBJECT = 'Text subject of the mail'
TEXT = 'Text of the mail'

gmail_sender = 'yourMail@gmail.com'
gmail_passwd = 'password'
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(gmail_sender, gmail_passwd)
BODY = '\r\n'.join(['To: %s' % TO,
                    'From: %s' % gmail_sender,
                    'Subject: %s' % SUBJECT,
                    '', TEXT])
try:
    server.sendmail(gmail_sender, [TO], BODY)
    print ('email sent')
except:
    print ('error sending mail')
server.quit()

第一天该软件运行良好,但现在我总是遇到来自gmail的身份验证错误:

   smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials o81-v6sm9180362wmo.38 - gsmtp')

我已经做的是:

我通过此链接停用了解锁验证码:

https://accounts.google.com/DisplayUnlockCaptcha

并且我通过此链接启用了安全性较低的应用程序:

https://www.google.com/settings/security/lesssecureapps

但还是一样,我再也无法发送电子邮件了。似乎没有Python软件问题,因为我在Go中编写了相同的软件,但仍然收到相同的错误。

1 个答案:

答案 0 :(得分:0)

已解决。我的登录错误。

相关问题