What is IMAP?
IMAP lets your mail app read and manage mail that stays on your provider's server. The app lists folders, fetches headers and bodies, and sets flags like read or starred. Because the real copy lives on the server, your phone, laptop and webmail all show the same inbox.
IMAP is how almost every mail app reads mail today. It does not send mail; that is SMTP's job. Its IDLE command lets the server push new mail to the app at once, without the app asking every few minutes.
Think of it like this. IMAP is like a locker at the post office that you can open from any branch. You look through the letters, mark some as read, move some to a shelf, and leave them all there. Whichever branch you visit next, the locker looks exactly as you left it.
Step by step
Normal
5 stepsKenji opens his mail app: it logs in, opens the inbox, lists new mail and downloads the one he taps.
Normal
5 stepsKenji opens his mail app: it logs in, opens the inbox, lists new mail and downloads the one he taps.
- 1
Connect with TLS
TCP and TLS on port 993
The app opens a TCP connection to port 993 and starts TLS at once. This is called implicit TLS, and RFC 8314 recommends it for mail.
- 2
Greeting and login
* OK, then LOGIN
The server greets with its capabilities. The app logs in, and every command carries a tag like a1 so replies can be matched.
- 3
Open the inbox
SELECT INBOX
SELECT opens a folder. The server says how many messages are in it and gives a UIDVALIDITY number, so the app knows whether its saved copy still matches.
- 4
List new mail
FETCH only the headers
The app asks only for From, Subject and Date of the newest mails. That is a few hundred bytes, not whole messages, so the list appears fast even on slow data.
- 5
Open one mail
FETCH the body, mark as seen
When Kenji taps a mail, the app fetches its body. The server marks it \Seen, and that flag is stored on the server, so every device shows it as read.
New mail push
4 stepsWith IDLE the app waits quietly and the server tells it the moment new mail lands.
New mail push
4 stepsWith IDLE the app waits quietly and the server tells it the moment new mail lands.
- 1
Start IDLE
a5 IDLE, server says + idling
Instead of asking every few minutes, the app sends IDLE and leaves the connection open. The server answers with a + line and then stays quiet.
- 2
Mail arrives
SMTP delivers into the mailbox
Ravi's mail reaches Kenji's provider by SMTP and is stored in the inbox. The IMAP server notices the new message.
- 3
Server pushes
* 1205 EXISTS
The server sends an untagged EXISTS line at once: there are now 1205 messages. The app ends IDLE with DONE and fetches the new header.
- 4
Back to waiting
IDLE again
The app goes back into IDLE. RFC 2177 says servers may drop an idle connection after 30 minutes, so apps restart IDLE before that, often every 29 minutes.
Two devices
3 stepsKenji reads and files a mail on his phone, and his laptop updates by itself.
Two devices
3 stepsKenji reads and files a mail on his phone, and his laptop updates by itself.
- 1
Both connected
Laptop idles, phone reads
The laptop sits in IDLE on the inbox. The phone has its own connection, with its own tags, to the same mailbox.
- 2
Read on the phone
STORE +FLAGS (\Seen)
Kenji opens the mail on his phone. The phone sets the \Seen flag on the server, and the server tells the laptop at once.
- 3
Move to a folder
UID MOVE to Archive
Kenji files the mail in Archive. The server moves it and tells the idling laptop that message 1205 is gone with EXPUNGE. Both screens now match.
Wrong password
3 stepsThe saved password is out of date, so the server refuses the login with NO.
Wrong password
3 stepsThe saved password is out of date, so the server refuses the login with NO.
- 1
Connect with TLS
Same start as always
TCP and TLS on port 993, then the server greeting.
- 2
Login refused
a1 NO [AUTHENTICATIONFAILED]
The server answers the tagged LOGIN with NO and a response code saying the credentials were wrong. The connection stays open so the app can try again.
- 3
App stops
LOGOUT and ask Kenji
A good app does not keep retrying the same wrong password, since servers lock accounts after many failures. It logs out and asks Kenji to sign in again.
Myths and mix-ups
- IMAP does not download all your mail to the device; it keeps the real copy on the server and fetches what you open.
- Deleting a mail on one IMAP device does delete it everywhere, because there is only one copy.
- IMAP does not send mail; your app uses SMTP for that.
- Push mail does not need a special service; IMAP IDLE keeps a quiet connection open and the server speaks when mail arrives.
Try it yourself
Run these on your own computer to see IMAP at work.
Talk to an IMAP server
openssl s_client -connect imap.example.com:993 -crlf -quietReplace the host with your provider's IMAP server. Type a1 CAPABILITY and press Enter, then a2 LOGOUT.
Check a mail server's certificate
openssl s_client -connect imap.example.com:993 -servername imap.example.com </dev/null | openssl x509 -noout -subject -datesShows who the certificate is for and when it expires.
Watch the commands
Turn on your mail app's connection log, then refreshMany desktop mail apps can log IMAP traffic in their troubleshooting settings. Look for SELECT, FETCH and IDLE.
IMAP at a glance
- Layer
- Application (7)
- Port
- 993 (TLS from the start); 143 with STARTTLS
- Transport
- TCP
- Format
- Text lines with tags, server data marked with *
- Current version
- IMAP4rev2, RFC 9051 (2021)
- Push
- IDLE command, server tells the app about new mail
- First defined
- 1986, IMAP4 in 1994
Defined inRFC 9051RFC 3501RFC 2177RFC 8314RFC 6851
Header fields
What IMAP puts in its messages, with example values from the stories above.
IMAP
- Tag
*A star marks untagged data: extra information the server sends along the way.- Line
OK [CAPABILITY IMAP4rev2 IMAP4rev1 AUTH=PLAIN IDLE MOVE] imap.example.com readyIMAP4rev2 is the current version, RFC 9051. Listing IMAP4rev1 too keeps older apps working.
Test yourself
Which port does IMAP with TLS from the start use?
Questions people ask
What is the difference between IMAP and POP3?
IMAP keeps mail on the server and syncs it across devices, folders and read status included. POP3 usually downloads mail to one device and often deletes it from the server.
What are the IMAP server settings for my email?
Usually the host is imap. followed by your provider's domain, port 993, SSL/TLS on, and your full email address as the username. Check your provider's help page for the exact values.
Is IMAP secure?
Yes, when used on port 993 or with STARTTLS on 143. The password and mail travel inside TLS. Without TLS, servers should refuse the login.
Why is my IMAP mailbox full when my phone has space?
With IMAP the mail lives on the server, so the server's storage limit is what fills up. Delete or archive large mails to free space.
Does IMAP support push notifications?
Yes, with the IDLE command. The app waits on an open connection and the server tells it the moment new mail arrives.