How Email Works

(A look at what happens behind the scenes)

A look at what happens behind the scene, when your computer tells you, “You have mail.” (Sometime in 2002 / 2003)

At one point in time, e-mail was all about simply copying a message from one system to another. However, with the phenomenal growth of the Net, the addition of differnt types of networks and the ever increasing load of messages the typical e-mail service is substantially more complex today.

Here is a brief look at what happens behind the scenes - when you send mail or when your computer tells you - “You have mail.”

(Note: In this article, we look at SMTP based e-mail over TCP/IP networks - which accounts for the bulk of e-mail transfer across the Internet)

Components of a Mail System

An electronic mail system is made up of the following components:

Message User Agents (MUA)

MUAs are a user’s interface into the mailing system. These are programs that the typical user is most familiar with. And MUAs are more commonly referred to as e-mail clients. Reading, composing, storing, forwarding, deleting and other operations on messages are carried out by users using MUAs. Examples of MUAs include Netscape Messenger, Eudora, Outlook Express, Pine, mail, mailx, etc.

Message Transport Agents (MTA)

These are programs that have the responsibilty of accepting outgoing mail and delivering it to its final destination. This is where all the real action takes place and in a sense the MTAs form the heart of the e-mail communication system.

Message Delivery Agents (MDA)

These programs form the end point of communication of an e-mail’s journey. They are responsible for placing incoming e-mail into the proper users mailbox. There may be multiple MDAs on a system, with separate agents for local mail delivery and for mail coming in from remote systems. It may also be interesting to note that some MUAs are capable of performing local deliveries by themselves.

Parts of a mail message

A mail generally consists of two parts: a header and a body. The body is the text that the user writes - the actual message. All the “junk” that you see above the body (while viewing a message) is the header.

In all frankness that “junk” is what is more important to the mailing system than the body itself. The header specifies control or administrative information. This information includes the sender’s and recipient’s address, date, subject line, etc.

Usually the necessary header fields are generated by the e-mail client that the user uses. The local MTA may add some of its own when it accepts the message from the MUA.

The header precedes the body and is separated by a blank line. As the message travels across the Internet, MTAs along the travel-path may (and generally do) transform the header. This is most commonly done by time-stamping the message as it is received. Therefore headers can be an invaluable aid when debugging an erratic message transation.

For the technically inclined, more details about header format, etc. can be found in RFC 822.

How does mail traverse the Net?

The process of directing an e-mail message from the sender to the receiver is called mail routing (not to be confused with IP level routing).

A message created in an e-mail client is “injected” into the mail system. This is done by either using a program supplied by the MTA to the e-mail client or by the e-mail client talking directly to the MTA using SMTP (Simple Mail Transfer Protocol) In this case the MTA could be on the local network or on a remote host, such as when you are connected to your ISP.

MTAs accept the message from the MUAs, inspect it to determine the recipients to make routing decisions and then start the communictaions that speed your mail towards the intended recipients. The default behaviour for an MTA is to look up the destination host’s IP address and attempt to perform a direct delivery.

In real life, a message may be handled by multiple MTAs on the way to its destination. At each “hop” the corresponding MTA will time-stamp the message. MTAs communicate with each other using SMTP. They use control information (also referred to as the envelope) to transfer the actual data (made up of the header & body).

For incoming mail, most sites have a mail server with high-availabilty and sufficient capacity to handle the expected load. Mail distribution then takes place locally. The DNS record of the domain will have an MX record (Mail eXchanger) that tells the rest of the Internet that the host specified by the MX is willing to accept e-mail for this domain. A domain could have multiple mail hosts servicing it. Each host has a corresponding MX entry as well as a “preference” number associated with it, with lower preference numbers indicating higher priority.

Almost undoubtedly, the most popular MTA in the world today is “sendmail”. Of course, it no longer has the distinction of being the only one. With the Internet boom, there is an ever expanding choice of MTAs. qmail, secure mailer, exim, smail are examples of some other well known MTAs.

Eventually the message arrives at its destination. The receiving MTA determines that the recipient is “local” and accepts the message into the system. Depending on the specific MTA (and system) various actions are possible at this point. For example, the message addressee could be an alias (a nickname for an actual account), which would get translated to the real recipient. (Simple mailing lists can be built this way.)

Finally the message is handed over to the MDA (delivery agent), which then has the responsibilty of delivering the message to the user’s mailbox. At this stage again, depending on the specific delivery agent fancy actions like automatic filtering and filing, vacation replies, etc. can take place.

You have mail

We have come full circle back to the MUA. When the user fires up his or her e-mail client he or she is informed about the waiting new mail. In the case of user agents like pine or mailx, the user’s mailbox (which is a file on the system in a pre-defined, standard format) is processed.

In the case where the user has to connect to a mailserver, the message is retrieved using a protocol like POP3 (Post Office Protocol) or IMAP (Internet Mail Access Protcol). POP3 is currently the most widely used protocol for message retrieval. IMAP has its own set of advantages and is slowly gaining acceptance. But more about them in another article…

A Simple Illustration

Lets say that I (Sharad Popli, sharad@qlcomm.com) on host QLC, want to send a message to Bill (Bill Gates, bill@microsoft.com) on host MSOFT. For the purposes of this illustration we assume that both QLC & MSOFT are permanently connected to the Internet.

  1. I start up Netscape Messenger, specify the recipient, subject and type in some data. This is what it could look like:

    To: bill@microsoft.com

    Subject: Acquisition

    How about a take-over?

  2. I say “Send”. At this time, my e-mail client may add in a few more header fields like Date, Message ID, etc. The MUA then puts the header and body into a file, separated by a blank line and then invokes sendmail to inject the message into the local mail system.
  3. Sendmail timestamps the message, examines the header and determines that the message is intended for a remote recipient. It then opens a dialogue with microsoft.com and proceeds to begin transfer of the message (using enevlope information as well as the actual message)
  4. For a moment now assume that Bill has resigned (very unlikely :)) and is no longer with Microsoft, and theerfore there is no user called “bill” at microsoft.com. The host MSOFT will send a bounce message to sharad@qlcomm.com informing him of the problem.
  5. On the other hand, if MSOFT accepts the message, it will realise that the recipient is local. Now for a moment assume that Bill has been receiving a LOT of mail (very likely) and his mailbox is full. The MSOFT MTA will send a bounce message back to sharad@qlcomm.com
  6. Finally lets assume that all is well at Redmond - Bill hasn’t resigned and he hasn’t exceed his mail quota. The MSOFT MTA accepts the message and hands it over to the MDA to complete the delivery into Bill’s mailbox.
  7. Next morning, Bill fires up his MUA (generally Outlook Express :)) and he sees my message. He hits the reply button…

And now, its time for me to go check if I have mail…