Skip to content

Instantly share code, notes, and snippets.

@PanosJee
Created July 19, 2010 22:25
Show Gist options
  • Save PanosJee/482146 to your computer and use it in GitHub Desktop.
Save PanosJee/482146 to your computer and use it in GitHub Desktop.
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