How to test IMAP commands against the IMAP service


You may wish to test IMAP commands against the IMAP service. This article decribes how this can be done. If a non-secure connection is available to the service, you can use the Telnet command on a Microsoft Windows PC to connect to the service and issue commands. If you wish to do this over a secure connection you can use OpenSSL and connect to the service.


To connect to the IMAP service over a non-secure port, you can open a command prompt and enter (assuming it is listening on the default port 143):

telnet servername 143

To connect using OpenSSL to a secure port, such as 993:

openssl s_client -connect servername:993

If you are using a non-secure port, but STARTTLS enabled for IMAP:

openssl s_client -starttls imap -connect servername:143

Once a connection is made, you will see a welcome message. A login can then be performed with the command:

1 login username password

The 1 just a string which identifies the IMAP command, so you can match the response. You can always just use 1 or another string for this article. After login, folders can be selected, message information retrieved, etc. A few useful commands are:

1 list "" *

This will list all the folders.

1 select folder

This will select a folder where you can then do message specific requests, such as the on below, which will give information about each message in the folder:

1 fetch 1:* all

Or you can retrieve a specific message:

1 fetch 1 (body[])

You can see what IMAP clients are doing in the IMAP Activity logs on the mail server. This will list the commands sent by the IMAP clients. The logs do omit the first string (1 in the examples above), so you need to add this when sending a command. Check the RFC for IMAP if you need further details on what commands are available. Some examples are:

To set message as read:

1 store 1 +flags (\Seen)

To make a connection listen to changes on a folder:

1 idle



OpenSSL for Microsoft Windows:

IMAP RFC 3501:


Class:HOWTO: Product Instructions
Revised:Wednesday, July 29, 2020