简体   繁体   English

我无法通过python在gmail上进行身份验证

[英]I can't authenticate at gmail via python

I'm trying to send an email via gmail: 我正在尝试通过gmail发送电子邮件:

  msg = MIMEMultipart()
  msg["From"] = "to@fdsfds.com"
  msg["To"] = ", ".join(recipients_array)
  msg["Subject"] = subject
  msg.attach(MIMEText(msg_body))


  # server = smtplib.SMTP("smtp.gmail.com", 587)
  server.ehlo()
  server.starttls()
  server.ehlo()
  server.login(my_gmail_address, my_gmail_password) # error here

  server.sendmail(my_gmail_address, recipients, msg.as_string())
  server.close()

And the error is: 错误是:

Traceback (most recent call last):
    # .......
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbuZg\n5.7.14 fsfdsfds-kK\n5.7.14 fdsfdsfds-CyIaJn4-TUONIr_gHn9\n5.7.14 gfdgfd-543543\n5.7.14 aaaa> 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 d8sm43303847pas.14 - gsmtp')

I'm authenticated in a browser at gmail. 我在gmail浏览器中通过了身份验证。

As explained here you might need to change your security settings to enable access for less secure apps. 如此处所述您可能需要更改安全设置以启用对安全性较低的应用程序的访问。

Go to https://www.google.com/settings/security/lesssecureapps to turn on access to less secure apps. 转到https://www.google.com/settings/security/lesssecureapps以打开对安全性较低的应用程序的访问。

If that doesn't fix the problem, you should read the information referenced in the traceback's error message: https://support.google.com/mail/answer/78754 如果仍不能解决问题,则应阅读回溯错误消息中引用的信息: https : //support.google.com/mail/answer/78754

It is most likely an issue with authentication like mhawke suggested. 很有可能是mhawke建议的身份验证问题。

For a list of common errors as well as a much more convenient library, have a look at yagmail . 有关常见错误的列表以及更加方便的库,请查看yagmail

Syntax would look like: 语法如下:

import yagmail
yag = yagmail.SMTP(username, password)
yag.send("toaddr@gmail.com", "this subject", "text content")

Full disclosure: I developed yagmail. 全面披露:我开发了yagmail。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM