代码之家  ›  专栏  ›  技术社区  ›  PanosJee

gmail smtp+xoauth神秘

  •  2
  • PanosJee  · 技术社区  · 15 年前

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

    我正在对gmail进行身份验证,我得到了这个答复

    reply: '235 2.7.0 Accepted\r\n'
    

    按预期发送XAUTH字符串后( 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'
    

    有什么线索吗?

    1 回复  |  直到 12 年前
        1
  •  3
  •   PanosJee    14 年前

    问题在于您如何进行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))
    

    您可以创建xoauth_字符串,如Google示例中所示。之后,您可以使用smtp_conn发送电子邮件。如果你有什么问题,请告诉我。您可以在以下位置找到一些示例代码: https://github.com/PanosJee/xoauth