223
Chapter 12
Building and Parsing E-Mail
This is the first of four chapters on the important topic of e-mail. This particular chapter does not discuss network
communication. Instead, it sets the stage for the next three:
• This chapter describes how e-mail messages are formatted, with a particular focus on the
correct inclusion of multimedia and internationalization. This establishes the payload format
for the protocols outlined in the subsequent three chapters.
• Chapter 13 explains the Simple Mail Transport Protocol (SMTP), which is used to transport
e-mail messages from the machine on which they are composed to the server that holds the
message, making them ready for reading by a particular recipient.
• Chapter 14 describes the old, poorly designed Post Office Protocol (POP) by which someone
who is ready to read their e-mail can download and view new messages that are waiting in
their in box on their e-mail server.
• Chapter 15 covers the Internet Message Access Protocol (IMAP), which is a better and more
modern option for locally viewing e-mail that is being hosted for you on your e-mail server.
Not only does IMAP support fetching and viewing, but it also lets you mark messages as read
and store them in different folders on the server itself.
These four chapters, as you can see, are in an order that suggests the natural lifespan of an e-mail. First, an e-mail
is composed from various pieces of text, multimedia, and metadata, such as its sender and recipient. Then SMTP
carries it from its place of origin to its destination server. Finally, a protocol like POP or IMAP is used by the recipient’s
e-mail client—commonly Mozilla Thunderbird or Microsoft Outlook—to pull a copy of the message to their desktop,
laptop, or tablet for viewing. Be aware, however, that this last step is becoming less common: many people today
read their e-mail through webmail services, which allow them to log on with a web browser and view their e-mails
rendered as HTML without the e-mails ever leaving the e-mail server. Hotmail was once very popular, while Gmail is
perhaps the largest such service today.
Remember, whatever happens to an e-mail later—whether you use SMTP, POP, or IMAP—the rules about how
e-mail is formatted and represented are exactly the same. Those rules are the subject of this chapter.
E-Mail Message Format
The famous RFC 822 of 1982 reigned for almost 20 years as the definition of e-mail until finally requiring an update.
This update was provided by RFC 2822 in 2001 before being itself superseded in 2008 with the issuing of RFC 5322.
You will want to refer to these standards when you are tasked with writing very serious or high-profile code for dealing
with e-mail messages. For the purposes here, only a few facts about e-mail formatting need immediate attention.