Here is an example of processing your GMail IMAP email in Python.

The script below will:

  • login to GMail account using IMAP
  • open your Inbox
  • retrieve and print all messages
  • close mailbox
  • logout
# Script adapted from Corey Goldberg
#!/usr/bin/env python import imaplib USER = '' PASSWORD = 'xxx' mail = imaplib.IMAP4_SSL('', 993) mail.login(USER, PASSWORD)'Inbox') status, data =, 'ALL') for num in data[0].split(): status, data = mail.fetch(num, '(RFC822)') print 'Message %s\n%s\n' % (num, data[0][1]) mail.close() mail.logout()