Previous: 11.10.1 IMAP4 Objects Up: 11.10 imaplib Next: 11.11 nntplib


11.10.2 IMAP4 Example

Here is a minimal example (without error checking) that opens a mailbox and retrieves and prints all messages:

import getpass, imaplib
M = imaplib.IMAP4()
M.login(getpass.getuser(), getpass.getpass())
M.select()
typ, data = M.search(None, 'ALL')
for num in data[0].split():
 typ, data = M.fetch(num, '(RFC822)')
 print 'Message %s\n%s\n' % (num, data[0][1])
M.logout()


Previous: 11.10.1 IMAP4 Objects Up: 11.10 imaplib Next: 11.11 nntplib
Release 2.2.3, documentation updated on 30 May 2003.
See About this document... for information on suggesting changes.

AltStyle によって変換されたページ (->オリジナル) /