2010-07-27 62 views
2

我正在使用python smtplib和xoauth,並且正在嘗試發送電子郵件。 我使用發佈的谷歌代碼:http://code.google.com/p/google-mail-xoauth-tools/source/browse/trunk/python/xoauth.pyGmail SMTP + XOAuth神祕

我其實鑑別針對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' 

任何線索?

回答

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)) 

您創建xoauth_string在從谷歌的例子。之後,您可以使用smtp_conn發送您的電子郵件。如果您有任何問題,請告訴我。你可以在https://github.com/PanosJee/xoauth

找到一些示例代碼