How to test IMAP commands against the IMAP service


If you want to test IMAP commands against the IMAP service, then this document perfectly suits you. If a non-secure connection is available to the service, you can opt to use the Telnet command on a Microsoft Windows PC to connect to the service and issue commands. If you want to perform this over the safest connection then you can opt for OpenSSL and connect to the service.


For connecting the IMAP service over a non-secure port, you use the command prompt and enter (assuming it is listening on the default port 143):

telnet servername 143

Use OpenSSL to connect a secure port, like 993:

openssl s_client -connect servername:993

You can use a non-secure port, but STARTTLS allowed for IMAP:

openssl s_client -starttls imap -connect servername:143

After fixing the connection, you’ll get the welcome message. A login can be done with the command:

1 login username password

The 1 is just a string that tells the IMAP command to match the response. Use 1 or another string for this document. After login, you can select the folders and also retrieve the message information, etc. A beneficial command is:

1 list “” *

This will list all the folders.

1 select folder

By selecting the folder will allow you to send the message on specific requests, the example below will provide the information about each message in the folder.

1 fetch 1:* all

Or you can retrieve a specific message:

1 fetch 1 (body[])

You can check the status of IMAP clients and their activities via IMAP Activity logs on the mail server. Through, this you’ll get the list of commands which is sent by the IMAP clients. The logs will skip the first string (1 in the examples above), so you are required to add this when sending a command. Check the RFC for IMAP if you require more details on what commands are available. Some examples are:

To set the message as read:

1 store 1 +flags (\Seen)

To approve the connection observe the changes into the folder.

1 idle

Leave a Reply