Test an IMAP Mailserver

To Test an IMAP Mailserver from Linux you only need an open terminal, telnet or openssl installed. Then it is simply a matter of opening a connection to your server and sending it some commands. It is the same commands that your GUI mail client will be doing.

To open a connection you can use either telnet or openssl if the connection is encrypted.

telnet mail.dragon.lab imap
openssl s_client -connect mail.dragon.lab:993

The above openssl command returns the ssl certificate you can stop that from happening by using the -quiet flag.

Both of the commands above should return message a message

* OK Dovecot (Ubuntu) ready.

The following listing shows how to find out the directories available on the server for the user you logged in with and how to grab the first email from the server.

  • The commands you type are in bold.
  • They can be in upper or lower case.
  • The number preceding each command can be anything.
    • It is returned by the client so you can check the response is from your last command.
    • I have used a count from 1.
  • Any text after the command can be in quotes ” to enclose escape characters or white space.

1 LOGIN fred@dragon.lab fredsmailpassword
1 OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS SPECIAL-USE BINARY MOVE] Logged in
2 LIST “” “*”
* LIST (\HasNoChildren) “.” Drafts
* LIST (\HasNoChildren) “.” Sent
* LIST (\HasNoChildren) “.” Trash
* LIST (\HasNoChildren) “.” INBOX
2 OK List completed.
3 EXAMINE INBOX
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS ()] Read-only mailbox.
* 1 EXISTS
* 1 RECENT
* OK [UNSEEN 1] First unseen.
* OK [UIDVALIDITY 1410627523] UIDs valid
* OK [UIDNEXT 12229] Predicted next UID
* OK [NOMODSEQ] No permanent modsequences
3 OK [READ-ONLY] Examine completed (0.001 secs).
4 FETCH 1 BODY[]
* 1 FETCH (BODY[] {1629}
Return-Path:
Delivered-To:
Received: from mail.dragon.lab
by mail.dragon.lab (Dovecot) with LMTP id lscABC9hHKjdCgAAEtR2Vw
for ; Sat, 10 Dec 2016 15:49:19 +0000
Received: from localhost (localhost [127.0.0.1])
by mail.dragon.lab (Postfix) with ESMTP id B9C4E40D02
for ; Sat, 10 Dec 2016 15:49:19 +0000 (GMT)
X-Virus-Scanned: Debian amavisd-new at dragon.lab
X-Spam-Flag: NO
X-Spam-Score: -1
X-Spam-Level:
X-Spam-Status: No, score=-1 required=6.31 tests=[ALL_TRUSTED=-1]
autolearn=ham autolearn_force=no
Received: from mail.dragon.lab ([127.0.0.1])
by localhost (mail.dragon.lab [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id m6M1uA3-zLiJ for ;
Sat, 10 Dec 2016 15:49:18 +0000 (GMT)
Received: from [192.168.0.9] (unknown [192.168.0.9])
(using TLSv1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits))
(No client certificate requested)
(Authenticated sender: fred@dragon.lab)
by mail.dragon.lab (Postfix) with ESMTPSA id D8A7A40D01
for ; Sat, 10 Dec 2016 15:49:17 +0000 (GMT)
To: Fred Bloggs
From: Fred Bloggs
Subject: testing the mail server
Message-ID: <7e1b96cd-ee38-35a7-8fa4-867d0e571c6a@dragon.lab>
Date: Sat, 10 Dec 2016 15:49:17 +0000
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

Our first email message!

)
4 OK Fetch completed.
5 LOGOUT
* BYE Logging out
5 OK Logout completed.
Connection closed by foreign host.

For a full list of IMAP commands and their expected return values see this page INTERNET MESSAGE ACCESS PROTOCOL – VERSION 4rev1

Now you can test an IMAP mailserver from the command line.

Leave a Reply

Your email address will not be published. Required fields are marked *