February 2006
Intermediate to advanced
648 pages
14h 53m
English
The imaplib module provides a low-level client-side interface for connecting to an IMAP4 mail server using the IMAP4rev1 protocol. Documents describing the protocol, as well as sources and binaries for servers implementing it, can be found at the University of Washington’s IMAP Information Center website at http://www.cac.washington.edu/imap.
The following example shows how the module is used by opening a mailbox and printing all messages:
import getpass, imaplib, string
m = imaplib.IMAP4()
m.login(getpass.getuser(), getpass.getpass())
m.select()
typ, data = m.search(None, 'ALL' )
for num in string.split(data[0]):
typ, data = m.fetch(num,'(RFC822)')
print 'Message %s\n%s\n' % (num, data[0][1])
m.logout()See Also
poplib (p. 426),