Site icon Mailtrap

A Deep Dive Into IMAP: What Is It and How Does it Work?

Considering the times we live in, chances are that a day doesn’t go by without us receiving an email or two. But have you ever wondered how your emails reach your inbox?

One of the protocols responsible for fetching our messages is called IMAP. Although it might seem difficult to understand at first, don’t worry — I’ve got your back.

Today, I’ll explain the IMAP protocol in detail and show you the optimal methods of testing how it works, so you can check it out yourself.

What is IMAP?

IMAP, short for Internet Message Access Protocol, is a protocol that enables email clients to access and retrieve messages from servers over TCP/IP connection.

It was created by Mark Crispin in 1986 as an alternative to Post Office Protocol (POP), which was used to download messages from the email server to the local device. Unlike POP, IMAP works similarly to cloud email, as, instead of locally, it stores your messages, folder structure, etc., on the mail server.

Nowadays, we use the protocol’s fourth version, IMAP4, which introduced some quality-of-life features like mailbox management and message flogging. More precisely, we use the protocol’s first revision, IMAP4rev1, which is more refined than its predecessor and is defined by RFC 3501.

How does IMAP work?

Let’s look at it this way: think of the IMAP server as a library and your email client as a library card.

You would see a catalog (email headers) of books (emails) when you ‘log in’ with your card. 

You can request to see any books (open and download email messages), but since it’s maintained and updated by the librarian (IMAP server), the library catalog remains consistent whether you access it from your phone or laptop.

Your messages remain on the server unless you specifically want to download them, but you can nonetheless delete them as you wish.
Keep in mind that IMAP is a “pull protocol,” meaning it only retrieves incoming mail. If you’d like to learn more about a protocol used for sending email, read about Simple Mail Transfer Protocol (SMTP).

What IMAP is used for

IMAP has many functionalities, and it can help you:

The types of IMAP servers

IMAP servers can either be:

If you are looking for more control, customization options, and better integration capabilities with internal systems and databases for your customized solution, then the self-hosted IMAP servers are a no-brainer for you. But remember that self-managed servers are hard to set up and run.

Here’s what a Reddit user had to say about self-managed IMAP servers:

Whereas if you want to build an integrated system and automate email interactions for instance, you should consider Gmail as it offers APIs and various integration options you can use for these purposes. And don’t forget the reduced burden of maintaining the server infrastructure that comes with provider-based services.

Self-managedManaged (by the 3d party)
Difficult to set upEasy to set up
Data is stored on dedicated storage within the organizationData is stored on the cloud
Complete autonomy over configurationsUser-friendly 
Tailorable server settings and security measuresMaintenance-free
Cost-effective for large user basesHigh uptime and robust infrastructure
Better integration capabilitiesEasily scalable to accommodate your needs
Full control over data storage and security protocolsAccess to customer support and updates

Pros and cons of IMAP

Whether you plan to implement IMAP into your software projects or opt for integrating Gmail API, familiarizing yourself with the advantages and disadvantages of IMAP is crucial.

Here’s a breakdown of its pros and cons by Yaroslav, our deliverability expert, to lend you a hand.

Pros

Cons

IMAP ports

If you opt for IMAP email protocol, understanding its ports, communication endpoints responsible for moving email data between servers, is crucial. It will allow you to configure firewalls and security software, troubleshoot email connectivity issues, etc.

I’ve compiled a table for you. Take a look:

Port 143Port 993
The default, non-encrypted IMAP port numberThe encrypted port, also known as IMAPS, used for communications over an SSL/TLS connection
Less secure than 993 as it’s non-encrypted, meaning that usernames, passwords, or other sensitive information is vulnerable to cyber attacksBeing a more secure port, IMAPS ensures data is encrypted during transmission, which is a notable layer of security
Often used in internal networks where encryption isn’t a concernUsed as a standard by most webmail service providers

IMAP settings

Okay, now that you have a general idea of what IMAP is and how it works, why don’t we test it out by connecting to an email account and using some simple IMAP commands?

For this, I went with OpenSSL, which can create secure connections using SSL/TLS and protect your sensitive data when you send it in plaintext over the network.

Although many people use Outlook, Yahoo, or Apple Mail, for OpenSSL, I’ll use Gmail as an example here as it’s the most widely used service provider and, personally, I think, the most convenient.

So, just follow the next few steps:

  1. Install the latest version of OpenSSL
  2. Launch your command line interface
  3. Use the command openssl s_client -connect imap.gmail.com:993 -crlf to connect to IMAP server
    • If you want to test IMAP with another provider, like Outlook, simply replace gmail.com with the desired domain name in the command
    • If you use Windows OS, you should omit -crlf as it can lead to an error due to double conversion
  4. Wait for the server to display a greeting message
  5. Type CAPABILITY to request the server’s capabilities
  6. Use LOGIN “yourusername yourpassword” with your IMAP credentials
    • When signing in, make sure to use an account that has 2-Step Verification
    • Additionally, you must enable IMAP in the “IMAP access” section of your Google account settings
    • You also shouldn’t use your regular password, but instead your app password 
    • Last but not least, make sure there are no spaces in between any of the 16 characters generated in the provided password
  7. After successful login, type LIST “” “*” to list all folders.
  8. Use SELECT “INBOX” to open a specific folder.
  9. Fetch emails with a command like FETCH 1 FULL, where 1 is the message number
    • Replace 1 with the specific message number you wish to fetch 
    • FULL fetches the entire message data
  10. End the session with LOGOUT

Remember to add a unique tag in front of every command, such as “tag1, tag2, tag3” or “a1, a2 a3”, etc. For example: tag3 SELECT INBOX.

Learn more about email protocols

And that’s a wrap! 🌯

We’ve gone over how IMAP protocol works, what it’s used for, its pros and cons, and showed you how to test it out efficiently. Hopefully, you have a clearer picture of this ever-so-popular protocol.

IMAP is just a part of a greater email infrastructure that should serve the purpose of delivering your emails to recipient’s inboxes. Mailtrap email delivery platform, together with Email Testing and Email SMTP/API service accommodates the needs of any type of senders and delivers just in time.

Interested in learning more about email infrastructure? Check out our article on the differences between IMAP, POP3, and SMTP email protocols, which can help you choose the best protocol for your needs.

Thanks for reading!

Exit mobile version