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.
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:
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.