Gmail SMTP 登录身份验证失败(已更新)

Ala*_*iah 4 python gmail smtp smtpclient

尝试使用 SMTP 登录 Gmail 帐户时,出现以下错误消息:

SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted.
Run Code Online (Sandbox Code Playgroud)

导致错误的代码:

import smtplib

server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login("sending@gmail.com", "your_password")
message = "TEST"

server.sendmail("sending@gmail.com", "receiving@gmail.com", message)
server.quit()
Run Code Online (Sandbox Code Playgroud)

Ala*_*iah 9

自 2022 年 5 月起,Google 已禁用启用安全性较低的应用程序的功能。因此,之前启用安全性较低的应用程序的解决方案不再有效。

脚步:

  1. 进入您的发送电子邮件地址并进入设置。
  2. 找到两步验证并启用它。
  3. 在两步身份验证下,应该有一个标记为“应用程序密码”的选项卡。单击它,然后选择邮件作为应用程序和您选择的设备
  4. 使用从应用程序密码生成的密码作为您的 Gmail 帐户的密码。

致谢:链接至来源