Computer Networking › Section B · The application layer › Topic B.3
Electronic mail
Email is one of the internet's oldest applications and still one of its busiest. Unlike the web, it relies on several protocols working in relay: one to move messages between servers, others to let people read them, and DNS records to find servers and check who really sent a message.
The parts of the email system
Internet email has three main components. User agents are the programs people use to read and write messages, such as a phone's mail app, a desktop client or a webmail page. Mail servers hold each user's mailbox and keep an outgoing message queue. The Simple Mail Transfer Protocol (SMTP), defined today in RFC 5321, moves messages from server to server over TCP. Email is asynchronous: the sender and recipient never need to be online at the same time, because servers store each message until the next step can happen.
The journey of a message
When Ana at ana@riverschool.example writes to Tom at tom@hillclinic.example, five steps follow. 1. Ana's user agent submits the message to her own outgoing mail server. 2. That server asks DNS for the MX record of hillclinic.example, which names the domain's mail server. 3. It opens a TCP connection to that server, normally on port 25, and transfers the message with SMTP. 4. Tom's server stores it in his mailbox. 5. Later, Tom's user agent fetches it. Ana's server, not her laptop, does the delivery because it is always on: if Tom's server is down, it keeps the message in its queue and retries, typically for several days.
Inside an SMTP session
SMTP is a text protocol of commands from the client and three-digit reply codes from the server. After the TCP connection opens, the server greets with 220. The client introduces itself with EHLO, the modern form of HELO. MAIL FROM gives the sender's address and RCPT TO a recipient, repeated for each recipient. DATA, answered by 354, starts the message itself, which ends with a line holding only a full stop. A 250 reply means the step succeeded, and QUIT, answered by 221, closes the session. One connection can carry several messages. SMTP is a push protocol: the sending server pushes mail towards the receiver.
Worked example: reading an SMTP dialogue
Follow Ana's server (C) delivering to Tom's (S). 1. S: 220 mx.hillclinic.example ready, after the TCP connection opens. 2. C: EHLO out.riverschool.example; S: 250, listing extensions it supports, such as STARTTLS. 3. C: MAIL FROM:<ana@riverschool.example>; S: 250 OK. 4. C: RCPT TO:<tom@hillclinic.example>; S: 250 OK. 5. C: DATA; S: 354, meaning send the message. 6. C sends the header lines, a blank line, the body and finally a line with a single full stop; S: 250, the message is accepted. 7. C: QUIT; S: 221. Check: every client command got a reply code, and only the 354 reply invited the message text.
Message format: headers and envelope
The message sent after DATA has header lines, a blank line and a body. Common headers are From:, To:, Subject:, Date: and Message-ID:, and each server that handles the message adds a Received: line, leaving a record of its path. These headers are part of the message, separate from the SMTP envelope set by MAIL FROM and RCPT TO, which the servers use for delivery. The two can differ, which is how a mailing list delivers one message to many people. It is also why a From: line, on its own, proves nothing about who sent a message.
MIME: attachments and other languages
SMTP was designed for short lines of 7-bit ASCII text, so anything else must be encoded. Multipurpose Internet Mail Extensions (MIME) add headers such as Content-Type, for example text/html or image/jpeg, and Content-Transfer-Encoding. A multipart message bundles a plain-text body, an HTML version and attachments as separate parts. Binary files are usually converted with base64, which turns every 3 bytes into 4 text characters, so attachments grow by a third. The UTF-8 character set lets messages carry any language, and newer SMTP extensions also allow non-ASCII email addresses.
Worked example: sending a photo attachment
Ana attaches a 3 MB photo, where 1 MB is \(10^6\) bytes, and her upload link runs at 10 Mbit/s. 1. Base64 turns each 3 bytes into 4, so the attachment becomes \(3 \times \frac{4}{3} = 4\) MB. 2. MIME breaks the text into lines of 76 characters, each ending in two line-break characters, adding about 2.6%, so about 4.1 MB. 3. In bits: \(4.1 \times 8 = 32.8\) Mbit. 4. Upload time at full speed: \(32.8 \div 10 \approx 3.3\) s. Check: without encoding the photo would need only 2.4 s, so encoding adds over a third to the time. Mail servers often cap message size, and the cap applies to the encoded size.
Submission and encryption in transit
Port 25 is for server-to-server relay. User agents normally submit outgoing mail on port 587, or 465 with TLS from the start, and must log in, so a server relays only for its own users. Between servers, the STARTTLS command upgrades an SMTP session to TLS when both sides support it. That protects messages on each hop, but each server along the way still sees the plain message. End-to-end protection, where only the recipient can read the content, needs the tools covered in the topic "Securing e-mail".
Reading mail: IMAP, POP3 and webmail
SMTP only pushes mail, so recipients need a different protocol to pull it from their mailbox. The Internet Message Access Protocol (IMAP) keeps messages and folders on the server, so a phone, tablet and laptop all see the same mailbox and the same read or deleted status. The older Post Office Protocol version 3 (POP3) simply downloads messages, usually removing them from the server, which suits a single device. Both are normally used over TLS. With webmail, the user agent is a web page: the browser talks HTTPS to the provider, whose own servers send and receive with SMTP.
Checking the sender: SPF, DKIM and DMARC
Plain SMTP lets any server claim any sender, which spammers and phishers exploit. Three checks, all published as DNS TXT records, fight this. Sender Policy Framework (SPF) lists the servers allowed to send for a domain. DomainKeys Identified Mail (DKIM) adds a digital signature over chosen headers and the body, verified with a public key in DNS. Domain-based Message Authentication, Reporting and Conformance (DMARC) tells receivers what to do when checks fail, such as quarantine or reject, and asks them to send reports. Since 2024 Gmail and Yahoo have required these from senders of bulk mail.
Common mistakes to avoid
First, thinking SMTP delivers mail to the recipient's device; it moves mail between servers, and IMAP, POP3 or webmail does the last step. Second, assuming the sender's user agent contacts the recipient's server directly; its own server relays and retries. Third, trusting the From: header; it can be forged unless SPF, DKIM and DMARC checks pass. Fourth, forgetting that base64 makes attachments about a third larger. Fifth, believing STARTTLS gives end-to-end secrecy; servers still read the message. Sixth, confusing POP3, which usually downloads and deletes, with IMAP, which keeps mail on the server.
Key takeaways
Email uses user agents, mail servers and SMTP, a text push protocol over TCP. The sending server finds the recipient's server through its MX record, delivers on port 25 with EHLO, MAIL FROM, RCPT TO, DATA and QUIT, and queues and retries on failure. Messages have headers, a blank line and a body; MIME adds content types, multipart bodies and base64, which grows files by a third. Users submit on port 587 or 465 and read with IMAP, POP3 or webmail. STARTTLS encrypts each hop. SPF, DKIM and DMARC use DNS to authenticate senders.
Flashcards
Flashcard
The program used to read and write mail
Test your understanding
Question 1 of 5
Tom reads email on a phone and a laptop and wants both to show the same folders and read status. Which protocol suits him?
Question 2 of 5
How does Ana's mail server find the server that accepts mail for hillclinic.example?
Question 3 of 5
A user attaches a 6 MB file. Ignoring line breaks, roughly how large is it after base64 encoding?
Question 4 of 5
Why does a sender's own mail server, rather than the sender's laptop, deliver the message to the recipient's server?
Question 5 of 5
In an SMTP session, which command names a person the message is for?
