您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用imaplib和oauth与Gmail连接

使用imaplib和oauth与Gmail连接

这是一个使用oauth2模块通过oauth进行身份验证的示例,摘自自述文件

import oauth2 as oauth
import oauth2.clients.imap as imaplib

# Set up your Consumer and Token as per usual. Just like any other
# three-legged OAuth request.
consumer = oauth.Consumer('your_consumer_key', 'your_consumer_secret')
token = oauth.Token('your_users_3_legged_token', 
    'your_users_3_legged_token_secret')

# Setup the URL according to Google's XOAUTH implementation. Be sure
# to replace the email here with the appropriate email address that
# you wish to access.
url = "https://mail.google.com/mail/b/your_users_email@gmail.com/imap/"

conn = imaplib.IMAP4_SSL('imap.googlemail.com')
conn.debug = 4

# This is the only thing in the API for impaplib.IMAP4_SSL that has 
# changed. You Now authenticate with the URL, consumer, and token.
conn.authenticate(url, consumer, token)

# Once authenticated everything from the impalib.IMAP4_SSL class will 
# work as per usual without any modification to your code.
conn.select('IN@R_518_2419@')
print conn.list()

比使用干净一点xoauth

其他 2022/1/1 18:41:42 有530人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶