Processing GMail IMAP email
Join the DZone community and get the full member experience.
Join For FreeHere 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
#!/usr/bin/env python import imaplib USER = 'username@gmail.com' PASSWORD = 'xxx' mail = imaplib.IMAP4_SSL('imap.gmail.com', 993) mail.login(USER, PASSWORD) mail.select('Inbox') status, data = mail.search(None, '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()
Gmail
Processing
Published at DZone with permission of Corey Goldberg, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments