Gmail SMTP + XOAuth之谜
我正在使用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'
在发送我的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'
有人知道怎么回事吗?
1 个回答
4
问题在于你是如何建立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