What POP3 is
POP3 (Post Office Protocol version 3, RFC 1939) is used to download mail from a mailbox. SMTP carries the message to the server; POP3 (or IMAP) carries it from the server to the reader's program. It is a text dialogue over TCP, port 110: the client sends four-letter commands and the server replies +OK or -ERR.
Its model is download and delete: the message moves to the user's device and disappears from the server. It is simple and light, but it does not work well for reading the same mailbox from several devices; that is what IMAP is for.
The three states
| State | What happens | Commands |
|---|---|---|
| AUTHORIZATION | The client identifies itself | USER, PASS (or APOP, AUTH) |
| TRANSACTION | The client looks and downloads; marks messages for deletion | STAT, LIST, RETR, DELE, UIDL, TOP, RSET, NOOP |
| UPDATE | After QUIT, the server deletes what was marked and closes | QUIT |
RSET unmarks everything marked with DELE. TOP n k downloads the headers and the first k lines of a message, handy for a look without downloading it all.
How it works: from the greeting to the deletion
Five steps: the connection, the login, the mailbox contents, the download and the deletion.
Connection to port 110 and +OK
The script opens a TCP connection to port 110 on mx1, which is in Montreal: the SYN crosses SW1, R1 and R2, and the reply comes back with TTL 62. As in SMTP, the server speaks first: +OK Dovecot ready. Every POP3 reply starts with +OK (fine) or -ERR (error). The session is in the AUTHORIZATION state: it does not know who you are yet.
USER and PASS: the password in clear text
The script sends USER noc and the server replies +OK; then PASS N0c-Alertas-2026: the whole password, in clear text, across the WAN between Vancouver and Montreal. The script reads it from an environment variable so it is not written in the code, but that does not protect it on the network. Dovecot accepts it (+OK Logged in.) because in this lab it has disable_plaintext_auth = no; with its default value, it would refuse a login without TLS. The session moves to the TRANSACTION state.
STAT and LIST: what is in the mailbox
STAT replies with two numbers: 1 message and its total size in bytes. LIST gives the list of messages, one per line with its number and size, and ends with a line that holds only a period, like SMTP's DATA. The numbers (1, 2, 3…) are only valid during this session; to recognise a message across sessions there is UIDL, which gives a unique ID.
RETR: the whole message
RETR 1 brings the whole message. Besides From, To and Subject, written by EEM, it has what each server added along the way: two Received headers, one from mx2 (received from R1 with SMTP) and one from mx1 (received from mx2 with ESMTPS, that is, with TLS), and on top Return-Path, X-Original-To and Delivered-To, added by mx1 when it delivered it to the mailbox. Received headers are read bottom to top: they are the mail's path. It all travels in clear text to the laptop.
DELE and QUIT: download and delete
DELE 1 only marks the message (+OK Marked to be deleted.). On QUIT, the session moves to the UPDATE state and the server deletes the marked ones: +OK Logging out, messages deleted. If the connection dropped before QUIT, the message would stay in the mailbox. That is the POP3 model: mail is downloaded to one device and deleted from the server; IMAP, instead, keeps it on the server and syncs several devices. The secure version of the script uses POP3_SSL, on port 995 with TLS.
POP3 versus IMAP
| POP3 | IMAP | |
|---|---|---|
| Where mail stays | On the device that downloaded it | On the server |
| Several devices | Hard: each one downloads and deletes | Yes: they all see the same |
| Folders and flags (read, answered) | No | Yes, on the server |
| Ports | 110, and 995 with TLS | 143, and 993 with TLS |
Secure POP3
| Option | How it works | Port |
|---|---|---|
| POP3S | TLS from the first byte (implicit TLS, recommended by RFC 8314) | TCP 995 |
| STLS | Starts in clear text and the STLS command turns the connection into TLS (RFC 2595) | TCP 110 |
| Unencrypted | User name, password and messages readable; Dovecot refuses it by default (disable_plaintext_auth) | TCP 110 |
In Python, poplib.POP3_SSL uses port 995. Give it a context built with ssl.create_default_context() so it verifies the server certificate.
Frequently asked questions
Why is the message not deleted by DELE?
Because DELE only marks it. The server deletes the marked messages when it receives QUIT (UPDATE state). If the connection drops before that, everything stays as it was.
What are Received headers?
Each server that receives the message adds one on top, with who it got it from, when and with which protocol. Read bottom to top, they are the mail's path; they help diagnose delays and spot forged mail.
Can mail be left on the server with POP3?
Yes: just do not send DELE. Many programs do that and use UIDL to know which messages they already downloaded. Even so, folders and read flags are not synced.
What is APOP?
An old login variant that sends an MD5 hash instead of the password. It is considered insecure today; the right option is TLS (POP3S or STLS).
What you take away
- POP3 downloads mail from the server: TCP 110, or 995 with TLS.
- Replies start with +OK or -ERR; multiline ones end with a period.
- USER and PASS travel in clear text if there is no TLS.
- DELE marks; the server deletes on QUIT (UPDATE state).
- Received headers show the message's path, bottom to top.
- To read from several devices, use IMAP.
NEXT STEP
From this lesson to the CCNA 2.0 Course
Network services and their security are part of The House of Routing's CCNA 2.0 Course, with the mail and alerts of the Canadá Logística lab. We will let you know when it opens.
Upcoming protocol lessons
Sources
- RFC 1939 · Post Office Protocol - Version 3
- RFC 2595 · Using TLS with IMAP, POP3 and ACAP (STLS)
- RFC 8314 · Cleartext Considered Obsolete: Use of TLS for Email Submission and Access
- Python · poplib — POP3 protocol client
- Dovecot 2.3 · SSL Configuration (ssl, disable_plaintext_auth)
Lesson prepared with AI assistance and checked against the sources cited. The bytes of every packet are generated according to the standard and verified with an independent tool.