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 contents and format. You don’t normally need to
know about such acronyms when using common email tools; but
internally, programs like Microsoft Outlook 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 modules to simplify all
aspects of email processing. In this section, we explore the POP and
SMTP interfaces for fetching and sending email at servers, and the
rfc822 interfaces for parsing information out of
email header lines; other email interfaces in Python are analogous
and are documented in the Python library reference manual.
POP: Reading Email
I used to be an old-fashioned guy. I admit it: up until recently, I preferred to check my email by telneting to my ISP and using a simple command-line email interface. Of course, that’s not ideal for mail with attachments, pictures, and the like, but its portability is staggering -- because Telnet runs on almost any machine with a network link, I was able to check my mail quickly and easily from anywhere on the planet. Given that I make my living traveling around the world teaching ...