TapHow email works (1)

Consider an email that you send. It starts when you type it into a client program such as Thunderbird, Outlook Express or Hotmail. It then makes it way to your ISP. From there it goes to the recipients mail server where it is stored until they read it. Simple isn’t it. All except the last stage is controlled by SMTP; Simple Mail Transfer Protocol. Simple in this context is as in “Village Idiot” as we will see later.

An email is a plain text file consisting of some headers (consider this as the envelope) followed by the body which contains the letter. In theory no headers are required at all because you tell the courier who it is for but a destination line starting “To: ” followed by an email address is good. It would also be courteous if it had a “From: ” line and a “Subject: ” but they are not essential to the system. After the headers there is supposed to be a blank line before the body starts. At the end of the mail there will be a line containing a single “.” but you may not be able to see that when it arrives.

The email starts its journey going to your ISP mail server. It knows where that is because it is in your email client configuration. The conversation between the client and the server looks like this—the four letter codes are from the client, the server replies begin with a number.

220 mail.server.com Sendmail 8.6 ready at Mon, 10 Jul 2006 19:21:01
250 mail.server.com Hello goodclient [], pleased to meet you
        [yes, it really is this chatty—goodclient and the address are your client]
mail From: me@server.com
250 me@server.com ... Sender ok [note, it hasn't checked it really]
rcpt To: you@recipient.com
250 you@recipient.com ... Recipient ok
        [this gets minimum checking but it is important to get it right]
354 Enter mail, end with "." on a line by itself
From: me@server.com
To: you@recipient.com
Subject: greetings          [none of these are checked]

How are you today?
250 Jhub756hQ Message accepted for delivery [The random characters are an internal id]
        [now you can start again with a new "mail" or exit]
221 mail.server.com closing connection

For a bit of fun you don’t even need an email client, just connect to the mail server on port 25 using telnet and type the commands in by hand. It is rather tedious though and there is little room for error.

The first thing the mail server does is add a new header to the front “Received: from … by …” and perhaps a time stamp, recording where it came from; think of this as a postmark. It then uses the destination (from the “rcpt” command not the “To: ” header) to decide where the email should go next. It will look at the domain part of the address (after the “@”) and ask DNS (Domain Name Service) what the address of the mail server is—this is obtained from DNS “MX” (mail exchange) records. It then goes through the same chatter with the destination mail server.

When the email arrives, after adding its own “Received: ” header to the front, the destination mail server will check that it really does belong here and store it in the file, sometimes called the mail box corresponding to the user (the bit before the “@”) It will wait there for them to fetch it, usually using a different system called POP3 (Post Office Protocol v3). The POP3 server uses a similar set of 4 letter commands to list mail, retrieve it, delete it etc.

Apart from a bit of queuing to cope with delays, that is all a mail server does.

Note that during all this, almost all the headers are ignored. “From: ” is never used for instance and can say absolutely anything! “To: ” may sometimes be used if the message has to be queued but not otherwise. “Cc: ” (Carbon copy) headers are checked and processed as new destination addresses using the same process as above. “Bcc: ” (Blind copy) is stripped out very early before being processed like “Cc: ” so it remains invisible to everyone else.

Comments are closed.

^ Top