The server configuration this testing works on, is a Ubuntu machine, running Postfix, Courier, mySQL.. though telnet doesn’t really care what kind of mail server you’re using, it just cares that it’s configured properly. However, these commands I am typing into my SSH terminal window running on the newly configured (with IMAP) mail server.
As you work your way through the development cycle of a new mail server, it’s essential to test every step of the way. First off, it’s smart to test using:
telnet localhost 25
But, as you get further into the development with security features, you’ll also want to test the IMAP capabilities.
One bit of help troubleshooting, or even just monitoring for your, dare I say, pleasure, is to tail (monitor the log in real time) the connection log, which by default is set to /var/log/mail.log:
sudo tail -f /var/log/mail.log
I often also open two other SSH terminals, each tailing two other files:
sudo tail -f /var/log/mail.err
sudo tail -f /var/log/mysql/mysql.log
If you’re running a web server that also uses mySQL, it’ll be kind of hard to monitor that last log file, as it’ll be very busy (assuming you have web traffic). If you notice these files aren’t logging, you should refer to the proper documentation on turning on the logging.
Now, to test the IMAP capabilities on the newly configured mail server. First make sure that you’ve sent email to the user you will now attempt to login to your IMAP server with. I usually use telnet localhost 25 to send an email to an outside email, then I just reply to that test email. This automatically creates the proper folder structure for the new, most likely virtual, user. Now, to log in to test IMAP via Telnet, use:
telnet localhost imap
Which should give you the response:
Connected to localhost. Escape character is ‘^]’. * OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION STARTTLS] Courier-IMAP ready. Copyright 1998-2011 Double Precision, Inc. See COPYING for distribution information.
01 login <user@your.domain> <password>
01 OK LOGIN Ok.
This means you’ve successfully logged on. This is a good thing!
Now that you’re in here, you can play with some other commands.
To list the available folders:
02 list “” “*”
To select one of the folders that’s displayed by the previous command [most likely INBOX is one]
03 select “INBOX”
* FLAGS (Answered Flagged Deleted Seen Draft)
* OK [PERMANENTFLAGS (Answered Flagged Deleted Seen Draft *)] Flags permitted.
* 1 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1180039205] UIDs valid
* OK [UIDNEXT 3] Predicted next UID
3 OK [READ-WRITE] Select completed.
To read the email that exists, shown by *1 EXISTS, type:
04 fetch 1 all
Giving something along the lines of:
* 1 FETCH (FLAGS (Seen) INTERNALDATE ………
4 OK Fetch completed.
This, however, doesn’t allow you to see what’s actually in the email. To see the body of the email:
05 fetch 1 body[]
Which should give you the body of the message, terminated with:
05 OK Fetch completed.
So, if you’ve got this far, your IMAP server seems to be working!
Just logout:
06 logout
Which returns:
* BYE Logging out
6 OK Logout completed.
Connection closed by foreign host.