Testing IMAP4 + TLS + AUTH with cygwin (or linux), Thunderbird debug

From time to time I have to do some troubleshooting for the IMAP4 protocol on our Exchange infrastructure. Most of the clients are running Thunderbird. For this purpose you can do two things.

    • Start Thunderbird in debugging mode

As described in this wiki article, create a batch with the following content:

This will generate imap.log on your desktop, which you can monitor while Thunderbird is talking to the mail server.

    • Connect to IMAP on command line

You will need a linux box or have cygwin installed to do this. IMAP4 is listening on port 143.

You will see the certificate exchange passing by, and you will have a blinking cursor. From here you can do IMAP console commands, as described here or here, and elsewhere 🙂
For example, to log in as user123 with password foobar, do this: (important: do not mistype, you cannot backspace and correct!)

Server’s response, in case credentials are correct, will be

You can now let the server show you all available folders:

Server’s reply, as an example:

So, INBOX has 8 subfolders. Select one of the folders.

Server’s reply, with some details about the folder:

Let’s fetch one of the emails:

This will give you the whole of the first email, including headers, ending with

You’ve seen enough, so log out:

Server’s last words (for now 🙂

Testing SMTP + TLS + AUTH communication with cygwin or a linux machine

Ever felt the need to see what a mail server actually does when another mail server or a mail client (Thunderbird f.e.) connects to it? Easy to trace when the connection isn’t encrypted – but rarely happens today. So you will have to “play” mail client yourself from the command line, which turns out to be a bit tricky. An excellent article on the topic can be found here.

Quick summary:

You will either need access to a linux box or have cygwin installed – or have openssl windows binaries, but the Base64 stuff will be hard 😉 (Go ahead, just install cygwin, a serious admin cannot live without…!)

Step 1: create the authentication bits

replace “USERNAME123” and “PASSWORD456” with real data

Step2: connect to the mail server through openssl

Step3: after saying HELO or EHLO to mailserver, you have to authenticate

The part after the “PLAIN” is the token that was returned in Step 1.

If you get back some sort of 200+ return code from the mailserver, you can start babbling SMTP as usual.