2

我正在使用 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'

有什么线索吗?

4

1 回答 1

3

问题在于您如何进行 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找到一些示例代码

于 2010-11-24T07:27:44.637 回答