IMAP (Internet Message Access Protocol)
Definition
IMAP (Internet Message Access Protocol, RFC 3501) is an email retrieval protocol that allows a client to access email messages stored on a remote mail server. Unlike POP3, IMAP synchronizes the client with the server, so messages remain on the server and are accessible from multiple devices.
IMAP is the dominant email retrieval protocol for modern email clients and webmail.
IMAP vs POP3
| Feature |
IMAP |
POP3 |
| Message storage |
On server |
Downloaded to client (usually deleted from server) |
| Sync across devices |
Yes |
No |
| Folder management |
Server-side folders |
Local only |
| Partial download |
Yes (headers first) |
No (full message) |
| Search on server |
Yes |
No |
| Offline access |
Limited |
Full (downloaded messages) |
| Bandwidth |
Lower (sync only changes) |
Higher (download all) |
| Use case |
Multi-device, modern email |
Single device, offline access |
IMAP Ports
| Port |
Protocol |
Use Case |
| 143 |
IMAP (unencrypted) |
Legacy, not recommended |
| 993 |
IMAPS (TLS) |
Recommended, implicit TLS |
| 143 + STARTTLS |
IMAP + STARTTLS |
Upgrade to TLS |
IMAP Folder Structure
INBOX (default)
├── Sent (sent items)
├── Drafts
├── Trash
├── Spam/Junk
├── Custom folders:
│ ├── Work
│ ├── Personal
│ └── Archive
IMAP Commands (Simplified)
Client: a001 LOGIN user@example.com password
Server: a001 OK Login successful
Client: a002 SELECT INBOX
Server: * 15 EXISTS
Server: * 3 RECENT
Server: a002 OK [READ-WRITE] SELECT completed
Client: a003 FETCH 1:5 (BODY.PEEK[HEADER])
Server: * 1 FETCH (BODY[HEADER] {1234} ...)
Server: * 2 FETCH (BODY[HEADER] {567} ...)
Server: ...
Server: a003 OK FETCH completed
Client: a004 COPY 1:3 "Work"
Server: * 15 EXISTS
Server: a004 OK COPY completed
Client: a005 STORE 1 +FLAGS (\Deleted)
Server: * 1 FETCH (FLAGS (\Deleted \Seen))
Server: a005 OK STORE completed
Client: a006 EXPUNGE
Server: * 15 EXPUNGE
Server: a006 OK EXPUNGE completed
Client: a007 LOGOUT
Server: * BYE IMAP4rev1 server logging out
Server: a007 OK LOGOUT completed
IMAP in Infrastructure
| Component |
IMAP Role |
| Mail server |
Dovecot, Courier (IMAP server) |
| Email client |
Thunderbird, Outlook, Apple Mail |
| Webmail |
Roundcube, SquirrelMail |
| Email archiving |
IMAP for bulk email retrieval |
| Monitoring |
IMAP connection count, mailbox size |
IMAP Security
| Feature |
Description |
| STARTTLS |
Upgrade IMAP to TLS encryption |
| SMTP AUTH |
IMAP AUTH PLAIN LOGIN OAuth2 |
| Sieve |
Server-side email filtering (RFC 5228) |
| IMAP ID |
Client identification (RFC 2971) |
| ACL |
Access control lists for shared mailboxes |
| Quota |
Mailbox size limits (RFC 2087) |
- Smtp — POP3 is the alternative to IMAP |
- Tls — IMAP traffic filtering (port 993) |
- Email — IMAP is the email retrieval protocol |
References