Created
July 19, 2010 22:25
-
-
Save PanosJee/482146 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def connect_to_gmail(CREDENTIALS, email, oauth_token, oauth_token_secret): | |
""" | |
Call this function to get an authenticated IMAP connection | |
""" | |
consumer = OAuthEntity(CREDENTIALS[0], CREDENTIALS[1]) | |
access_token = OAuthEntity(oauth_token, oauth_token_secret) | |
xoauth_string = GenerateXOauthString( | |
consumer, access_token, email, 'imap', | |
None, str(random.randrange(2**64 - 1)), str(int(time.time()))) | |
# connect to imap | |
imap_conn = imaplib.IMAP4_SSL('imap.googlemail.com') | |
#imap_conn.debug = 3 | |
imap_conn.authenticate('XOAUTH', lambda x: xoauth_string) | |
imap_conn.select('INBOX') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment