Electronic Mail
Electronic mail, or email, is one of the internet's earliest and most enduring applications. It provides a fast, cost-effective, and asynchronous means of communication, allowing users to send and read messages at their convenience.
Email is fast, cost-effective, and supports attachments, HTML content, and embedded media.
The Core Components of the Email System
The internet email system is built on three key components:
User Agents (UAs): These are the applications that users interact with to read, compose, and manage their emails. (Desktop clients like Microsoft Outlook and Apple Mail, or web-based clients like Gmail).
Mail Servers: Like digital post offices. Each user has a mailbox on a mail server where incoming emails are stored. Also has a message queue to hold outgoing emails before they are sent.
SMTP (Simple Mail Transfer Protocol): This is the application-layer protocol used to send, or "push," email messages from sender's mail server to recipient's server. It runs on top of TCP to ensure reliable transmission.
SMTP (Simple Mail Transfer Protocol)
The Simple Mail Transfer Protocol (SMTP) is the standard protocol for sending email over the internet. It is a push protocol, meaning the sending mail server initiates the connection and pushes the message to the receiving mail server.
It operates over TCP port 25 and ensures reliable delivery of messages.
Sending an Email
The process of sending an email from a sender to a recipient generally follows these steps:
Composed message is sent using sender's User Agent.
UA sends the message to sender's mail server, where it is placed in an outgoing message queue.
Sender's mail server, acting as an SMTP client, opens a TCP connection to Recipient's SMTP mail server on port 25.
After an initial SMTP handshake, sender’s server transmits the email message over the established connection.
The recipient’s SMTP server receives the message and stores it in the recipient’s mailbox.
The recipient opens their email client (UA) and retrieves the message asynchronously from their mail server.
If the recipient's mail server is unavailable, the sender's mail server will queue the message and retry delivery periodically. Failure after multiple attempts leads to a bounce-back notification.
- SMTP does not use intermediate mail servers. If the recipient’s server is down, the sender reties periodically.
SMTP runs on top of TCP, ensuring reliable transmission and persistent TCP connection for sending multiple emails.
Each mail server runs both an SMTP client (to send mail) and an SMTP server (to receive mail).
- SMTP supports only 7-bit ASCII in the body, requiring multimedia files to be encoded (e.g. Base64)
Common SMTP Commands
Communication between SMTP servers uses a series of simple, text-based commands.
HELO: Initiates the connection.
MAIL FROM: : Specifies the sender's address.
RCPT TO: : Specifies the recipient's address.
DATA: Indicates that the message body is about to be sent.
.
Ends the message body (sent asCRLF.CRLF
).QUIT: Terminates the session.
Example SMTP Dialogue:
C: HELO crepes.fr
S: 250 Hello crepes.fr
C: MAIL FROM: <alice@crepes.fr>
S: 250 OK
C: RCPT TO: <bob@hamburger.edu>
S: 250 OK
C: DATA
S: 354 Start mail input
C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted
C: QUIT
S: 221 Closing connection
SMTP vs. HTTP: A Comparison
While both SMTP and HTTP are application-layer protocols used to transfer files using persistent TCP connections, they have fundamental differences.
Push vs. Pull:
- SMTP is a push protocol; the sender actively pushes the message to the receiver.
- HTTP is a pull protocol; the client pulls information from the server.
Data Format:
- SMTP was originally designed for 7-bit ASCII text. Any binary data, like images or attachments, must be encoded into ASCII.
- HTTP can handle different data types, including binary and multimedia content, natively without needing conversion.
Object Handling:
- SMTP sends an entire email content, including the body and all attachments as a single message.
- HTTP treats every object on a web page (like the HTML file, images, and scripts) as a separate entity, often requiring multiple request-response cycles.
The Structure of an Email Message (RFC 5322)
An email message itself has a standard format, defined in RFC 5322. It consists of two main parts, separated by a blank line:
The Header: This section contains metadata about the message. It is made up of several lines, such as:
From:
The sender's email address.To:
The recipient's email address.Subject:
A brief summary of the message content.
The Body: This is the main content of the message. Originally just plain text, it can now include HTML, images, and other rich media.
The header lines are part of the email message itself and are distinct from the SMTP commands used to transfer it.
Example Message Header Format
From: alice@crepes.fr
To: bob@hamburger.edu
Subject: Searching for the meaning of life.
Hello Bob,
This is a test email.
Mail Access Protocols
Simple Mail Transfer Protocol (SMTP) is excellent for sending or "pushing" email from sender's user agent to the sender's mail server and from server to server, it's not designed for retrieving (pull
) mail to local UA.
A user's device isn't always online, so a different type of protocol is needed to "pull" messages from an always-on mail server. These are known as mail access protocols.
The three main protocols used for this are POP3, IMAP, and HTTP (for web-based email).
POP3 (Post Office Protocol v3): Downloads mail from server and typically deletes it.
IMAP (Internet Mail Access Protocol): Allows viewing and managing messages directly on the server.
HTTP: Used by webmail services (e.g., Gmail via browser).
SMTP: UA → Sender’s Mail Server
SMTP: Sender’s Mail Server → Recipient’s Mail Server
POP3/IMAP/HTTP: Recipient’s Mail Server → Recipient’s User Agent
POP3 (Post Office Protocol v3)
POP3 is a simple, straightforward protocol designed to download emails from a server to a single local client using port 110 for communication.
POP3 operates in a "download-and-delete" mode by default. When a user connects, the client downloads all messages from the server to the local device and then deletes them from the server.
Phases: A POP3 session has three phases:
- Authorization (login),
- Transaction (
LIST, RETR, DELE
listing and retrieving messages, marking for deletion), - Update (on
QUIT
the server deletes messages marked for deletion from the server and closes session).
Best For: Users who access their email from only one computer.
Limitations: Because it moves emails off the server, it is poorly suited for checking email from multiple devices. Actions taken on one device (like reading or deleting a message) are not synchronized with any other device.
- No synchronization between multiple devices.
- Emails may be lost if the client device fails and download-and-delete mode is used.
- Passwords are often sent in plain text unless encrypted (e.g., using SSL).
POP3 is still widely supported but is gradually being replaced by more feature-rich protocols like IMAP
IMAP (Internet Message Access Protocol)
IMAP is a more modern and flexible protocol that allows users to view and manage their email directly on the server.
With IMAP, all messages and folders are kept on the server. When accessing email, the client synchronizes with the server. Actions are consistent across all devices.
Synchronization: Changes made on one device (e.g., reading an email on your phone) are reflected everywhere (e.g., it shows as read on your laptop).
Server-Side Management: Users can create, rename, and delete folders to organize their mail directly on the server.
Emails initially arrive in the INBOX folder but can be moved to custom folders without downloading them.
Partial Fetches: Clients can download just the message headers to save bandwidth and then fetch the full message content only when a user opens it.
It enables server-side search, allowing users to search messages based on specific criteria such as sender, subject, or date.
IMAP maintains state information across sessions, including: Read/unread status of messages, Flags and labels, Folder hierarchy and associations
IMAP uses TCP port 143 for standard communication and port 993 for secure (SSL/TLS) communication.
Best For: The vast majority of modern users who access their email from multiple devices, such as a phone, laptop, and tablet.
Web-Based Email (Using HTTP)
With the rise of services like Gmail and Outlook.com, a huge number of users access their email through a web browser. In this case, the mail access protocol is HTTP.
The user's browser acts as the mail client. It uses HTTP to send requests to and receive responses from the mail server. This allows users to read, write, and manage their email from any device with a web browser, without needing a dedicated email client application.
Even when a user sends an email from a web interface via HTTP, their mail server still uses SMTP to transfer that message to the recipient's mail server.
Comparison of Email Protocols
Feature | SMTP | POP3 | IMAP |
---|---|---|---|
Primary Use | Sending emails | Retrieving emails | Managing & syncing emails |
Protocol Type | Push (sends mail) | Pull (downloads mail) | Pull (syncs mail) |
Message Storage | Does not store messages | Messages are moved to the local device | Messages remain on the server |
Folder Support | No | No | Yes (server-side folders) |
Multi-Device Access | Not applicable | Limited | Full support and synchronization |
State Maintenance | Stateless | Stateless within a session | Maintains user state (e.g., read/unread) |
Common Ports | 25, 587 | 110 (standard), 995 (secure) | 143 (standard), 993 (secure) |