IMAP and POP3
IMAP and POP3 let mail clients fetch messages from a mailbox. IMAP keeps mail on the server and syncs folders; POP3 downloads and usually deletes. Both are text protocols with passwords in the clear unless TLS is used.
- OSI layer
- 7 Application
- Carried in
- TCP
- Ports
- 143/tcp (IMAP), 993/tcp (IMAPS), 110/tcp (POP3), 995/tcp (POP3S)
- Wireshark filter
imap || pop- Encrypted
- no
Packet structure
Both are line-based text protocols over TCP. IMAP prefixes each command with a client-chosen tag; the server answers with untagged lines (*) and finally a tagged OK, NO or BAD:
S: * OK [CAPABILITY IMAP4rev1 STARTTLS LOGINDISABLED] mail.example.com ready
C: a1 STARTTLS
S: a1 OK Begin TLS negotiation now
... TLS handshake, then capabilities again ...
C: a2 LOGIN alice "s3cret"
S: a2 OK [CAPABILITY IMAP4rev1 IDLE MOVE ...] Logged in
C: a3 SELECT INBOX
S: * 172 EXISTS
S: * OK [UIDVALIDITY 1698412345] UIDs valid
S: a3 OK [READ-WRITE] Select completed
C: a4 FETCH 172 (FLAGS BODY.PEEK[HEADER.FIELDS (FROM SUBJECT)])
S: * 172 FETCH (FLAGS (\Seen) BODY[...] {64}
S: From: Bob <bob@example.org>
S: Subject: Invoice
S: )
S: a4 OK Fetch completed
C: a5 LOGOUT
POP3 has no tags: one command, one +OK or -ERR reply.
S: +OK POP3 server ready
C: USER alice
S: +OK
C: PASS s3cret
S: +OK Logged in, 3 messages
C: LIST
S: +OK 3 messages
S: 1 2048
S: 2 15360
S: 3 912
S: .
C: RETR 1
S: +OK 2048 octets
S: ... message ...
S: .
C: DELE 1
C: QUIT
| IMAP command | Purpose | POP3 command | Purpose |
|---|---|---|---|
LOGIN, AUTHENTICATE | Log in (AUTHENTICATE PLAIN / XOAUTH2 is Base64) | USER + PASS, APOP, AUTH | Log in |
LIST, SELECT, EXAMINE | Folders, open one (EXAMINE read-only) | STAT, LIST, UIDL | Mailbox size, message list |
SEARCH, FETCH | Find and read messages | RETR, TOP | Read a message (or its first lines) |
STORE, COPY, MOVE, EXPUNGE | Flags, copy, move, delete | DELE | Mark for deletion |
APPEND | Upload a message (sent items, drafts) | ||
IDLE | Push: wait for new mail |
How it works
Mail arrives at the server by SMTP; the user’s client then fetches it:
- IMAP keeps everything on the server: folders, read/unread flags, and the same view on every device. Clients stay connected with
IDLE. - POP3 downloads messages to one device and usually deletes them from the server.
Both support implicit TLS (993, 995, recommended by RFC 8314) and STARTTLS on the plain ports.
In Wireshark
| Filter | Shows |
|---|---|
imap | IMAP on 143 (and 993 once decrypted) |
pop | POP3 on 110 |
imap.request.username | IMAP LOGIN commands (Wireshark extracts user name and password) |
pop.request.command == "PASS" | POP3 passwords |
imap.response.status == "NO" | Failed IMAP commands (incl. logins) |
pop.response.indicator == "-ERR" | POP3 errors |
imap.request contains "STARTTLS" | Encryption upgrades |
tcp.port in {993, 995} | IMAPS and POP3S (TLS) |
What normal looks like: clients on 993 (or 995) to your mail server, long-lived IMAP connections with IDLE. Clear-text logins on 143/110, many failed logins from one source, or logins from unusual countries to a cloud mailbox are signs of trouble. Port 143 or 110 to the internet from a workstation may be malware checking a mailbox for commands.
Security notes
- Clear-text credentials:
LOGIN,USER/PASSandAUTHENTICATE PLAINwithout TLS give the password to anyone on the path. Enforce implicit TLS and disable plain-text auth (LOGINDISABLED). - STARTTLS stripping and injection: an on-path attacker removes
STARTTLSfrom the capabilities, or injects commands before the TLS upgrade (CVE-2011-0411 style); implicit TLS avoids both. - Password spraying and brute force: IMAP and POP3 are “legacy authentication” that often bypasses MFA. Microsoft 365 and Google disabled basic auth for these protocols for that reason; block it where you can.
- Data theft: IMAP is a convenient way to download a whole mailbox with stolen credentials (e.g.
imapsync,offlineimap). - Mail-based C2: malware that reads commands from and writes results to a mailbox over IMAP blends in with normal traffic.
Versions and related
- IMAP4rev1 (RFC 3501) is what most servers speak; IMAP4rev2 (RFC 9051) is the current standard.
- POP3 (RFC 1939) has hardly changed since 1996.
- JMAP (RFC 8620/8621) is a modern JSON-over-HTTP replacement; Exchange ActiveSync, EWS and Microsoft Graph are the Microsoft APIs.
- SMTP sends mail; TLS protects it.