gpt4 book ai didi

python - Gmail SMTP + XOAuth 之谜

转载 作者:太空宇宙 更新时间:2023-11-04 01:42:39 25 4
gpt4 key购买 nike

我正在使用 python smtplib 和 xoauth,我正在尝试发送电子邮件。我正在使用 Google 发布的代码:http://code.google.com/p/google-mail-xoauth-tools/source/browse/trunk/python/xoauth.py

我实际上是针对 Gmail 进行身份验证,我收到了这个回复

reply: '235 2.7.0 Accepted\r\n'

按预期发送我的 XOAuth 字符串后 (http://code.google.com/apis/gmail/oauth/protocol.html#smtp)

当我撰写一封电子邮件并尝试发送时,出现以下错误

reply: '530-5.5.1 Authentication Required. Learn more at                              
reply: '530 5.5.1 http://mail.google.com/support/bin/answer.py?answer=14257 f10sm4144741bkl.17\r\n'

有什么线索吗?

最佳答案

问题在于您如何进行 SMTP 连接,这里是我的代码片段:

    smtp_conn = smtplib.SMTP('smtp.googlemail.com', 587)
#smtp_conn.set_debuglevel(True)
smtp_conn.ehlo()
smtp_conn.starttls()
smtp_conn.ehlo()
smtp_conn.docmd('AUTH', 'XOAUTH ' + base64.b64encode(xoauth_string))

您可以按照 Google 的示例创建 xoauth_string。之后,您可以使用 smtp_conn 发送您的电子邮件。如果您有任何问题,请告诉我。您可以在 https://github.com/PanosJee/xoauth 找到一些示例代码

关于python - Gmail SMTP + XOAuth 之谜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3347731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com