2.3 Electronic Mail in the Internet¶
This note explains how email works.
Email is an asynchronous communication medium. A high level-view contains three major components:
-
User agents
-
Mail servers
-
Simple Mail Transfer Protocol (SMTP)
Mail servers form the core of the email infrastructure. Each recipient has a mailbox located in one of the mail servers. A typical journey starts in the sender's user agent, then travels to the sender's mail server, and thentravels to the recipient's mail server, where it is deposited in the recipient's mailbox. If Alice's server cannot deliver to Bob's server, Alice's server holds the message in a message queue and attempts to transfer the message later, usually with reattempts every 30 minutes or so; if no success for a while, the server removes the message and notifies Alice.
SMTP¶
The principle application-layer protocol for Internet email. It uses a reliable data transfer service of TCP to transfer ail from the sender's mail server to the recipient's mail server.
SMTP has two sides: client (executes on sender's mail server) and server side (executes on recipient's mail server)
Suppose Alice wants to send Bob a simple ASCII message 1. Alice invokes her user agent for email, provides Bob's email address, composes a message, and instructs the user agent to send the message 2. Alice's user agent sends the message to her mail server, where it is placed in a message queue 3. Client side of SMTP, running on Alice's mail server, sees the message in the message queue. It opens a TCP conection to an SMTP server, running on Bob's mail server. 4. After SMTP handshking, the SMTP client sends Alice's message into the TCP connection 5. Bob's mail server uses the server side of SMTP and receives the message. Bob's mail server then places the message in Bob's mailbox 6. Bob invokes his user agent to read the message at his convenience.
Now let's take a closer look:
-
Client SMTP has TCP establish a connection to port 25 at the server SMTP. If server is down, the client tries again later.
-
When connection is established, server and client perform some application-layer handshaking. They introduce themselves before transferring information from one to another. SMTP clients indicates email address of sender, and the email address of the recipient
-
The client then sends the message. SMTP can count on reliable data transfer service of TCP to get the message to the server without errors.
-
Client repeats this process over the same TCP connection if it has other messages to send to the server; otherwise, it instructs TCP to close the conection.
Something like this happens with client (C) and server (S)
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM: <alice@crepes.fr>
S: 250 alice@crepes.fr ... Sender ok
C: RCPT TO: <bob@hamburger.edu>
S: 250 bob@hamburger.edu ... Recipient ok
C: DATA
S: 354 Enter mail, end with ”.” on a line by itself
C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 hamburger.edu closing connection
As part of the dialogue, client issued five commands: HELO (Hello), MAIL FROM, RCPT TO, DATA, and QUIT There is also a single period, which indicates the end of the message to the server.
Mail Message Formats¶
There may be peripheral header information like Bob's address, Alice's return address, date, etc. In an real mail. In email, there is also a header containing peripheral information that precedes the body.
A typical message headder looks like this:
From: alice@crepes.fr
To: bob@hamburger.edu
Subject: Searching for the meaning of life.
After the message header, there is a blank line, then the message body follows
Mail Access Protocols¶
There is a small problem with the approach discused. Recall that a mail server manages mailboxes and runs the client and server sides of SMTP. If Bob's mail server were to reside on his local host, then Bob's host would have to remain always on, and connected to the Internet to receive new mail, which arrives at any time. This is highly impractical.
Instead a typical user runs a user agent on the local host but accesses its mailbox stored on an always-on shared mail server. This mail server is shared with other users.
There are two common ways today for Bob to retrieve email from a mail server
- Using a Web-based email or smartphone app (like Gmail), user agent will use HTTP to retrieve Bob's email
- Internet Mail Access Protocol IMAP) is used with mail clients such as Microsoft Outlook.