Testing POP3 and IMAP servers from the command line in CMD or bash

It’s quite simple, really: POP3 (Exchange, dovecot etc) you know, IMAP (Exchange, dovecot, courier etc) you know — so this is just a recap, right? You know how to telnet into the machine — in Vista or Windows 7, you may need to install it separately using “Add/Remove Programs”, or just use Putty in Telnet mode…  otherwise, apt-get install telnet if it’s not on your machine (or yum install telnet)

POP3:

telnet SERVER 110
user USERNAME
pass PASSWORD
LIST

and you have a list of the messages RETR MESSAGENUM to get that specific message.

IMAP4:

telnet SERVER 143
? LOGIN username password
? LIST "" *
? SELECT mailbox
? STATUS mailbox (MESSAGES)

MESSAGES, UNSEEN, RECENT UIDNEXT UIDVALIDITY can be interchanged in the STATUS

And one of the following commands to view the a message 1 is the first message * is wildcard for all:
? FETCH 1 ALL # All IMAP headers
? FETCH 1 FULL # Full headers and body info
? FETCH 1 BODY # Body
? FETCH 1 ENVELOPE # Envelope
? FETCH * FULL # All email

To fully retrieve a message use:
? UID fetch 1:1 (UID RFC822.SIZE FLAGS BODY.PEEK[])