Section 14.3. Processing Internet Email


14.3. Processing Internet Email

Some of the other most common, higher-level Internet protocols have to do with reading and sending email messages: POP and IMAP for fetching email from servers,[*] SMTP for sending new messages, and other formalisms such as rfc822 for specifying email message content and format. You don't normally need to know about such acronyms when using common email tools; but internally, programs like Microsoft Outlook and webmail systems generally talk to POP and SMTP servers to do your bidding.

[*] IMAP, or Internet Message Access Protocol, was designed as an alternative to POP, but it is still not as widely available today, and so is not presented in this text. A major commercial provider used for this book's examples only provides POP access to email, for instance. See the Python library manual for IMAP server interface details.

Like FTP, email ultimately consists of formatted commands and byte streams shipped over sockets and ports (port 110 for POP; 25 for SMTP). But also like FTP, Python has standard library modules to simplify all aspects of email processing:

  • poplib and imaplib for fetching email

  • smptplib for sending email

  • The email module package for parsing and constructing email

The email package also handles tasks such as address parsing and date and time formatting, and additional modules handle more specific tasks (e.g., mimetypes to map filenames to and from content types). The module rfc822 provides an alternative headers parsing tool, but has been deprecated since Python 2.3 (email should be used today).

In the next few sections, we explore the POP and SMTP interfaces for fetching and sending email at servers, and the email package interfaces for parsing and composing email message text. Other email interfaces in Python are analogous and are documented in the Python library reference manual.




Programming Python
Programming Python
ISBN: 0596009259
EAN: 2147483647
Year: 2004
Pages: 270
Authors: Mark Lutz

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net