Retrieving mail manually using telnet

You can retrieve your e-mail manually using telnet. This might be handy in an emergency; for example, if you are away for a few days, your inbox fills up with a nasty mix of spam, viruses and virus bounces, and you only have a low-speed internet connection. You can view just the headers of the messages and delete any that aren't worth downloading. This information might also be useful if you need to write a custom e-mail client.

Have handy your mail server address (I'll use pop3.myisp.co.uk for this example), and your pop3 login and password  (let's say fred and laRge1. In a Unix or Unix-like system, at the command line, enter telnet pop3.myisp.co.uk 110

You can also use a GUI-based client. If so, be sure to set the port number to 110, which is the port used for POP3 sessions. If you have local echo off, it may be advisable to turn it on, as fixing and noticing errors that you type could be difficult.

You should see some kind of prompt from the server, such as Connected to pop3.myisp.co.uk. Escape character is '^]'. +OK Qpopper (version 4.0.4) at pop3.myisp.co.uk starting. &lt;14859.1078603175@pop3.myisp.co.uk>

POP3 is a human-readable protocol with machine-readable clues. The client (that's you, or more usually a mail client such as KMail)  gives commands to the server, and the server gives responses to the client. A response beginning with a plus sign + is a "good" response (the remainder of the line usually takes the form of a confirmation or prompt for the benefit of humans). A response beginning with "-" is a "bad" response, and the rest of the text is usually a meaningful error message that can be saved in a logfile. There are different POP3 server programmes, and they all have slightly different messages, so you may see something different when you try it, and of course your messages probably won't have the same lengths as in this example.

Anyway, first of all you need to login, using the USER command. Type USER fred and the server will issue a prompt for a password; +OK Password required for fred to which you should respond with the PASS command and your password; PASS laRge1 If the password was correct, you should see a summary of your messages. +OK fred has 2 visible messages (0 hidden) in 9513 octets. ("octets" is just another word for "bytes").

If you use the LIST command, you can see the length of each message; LIST +OK 2 visible messages (9513 octets) 1 4863 2 4650.

The full stop on a line by itself indicates the end of a multi-line response, but there should always be some clue in the first line as to how long the response is going to be. For each message there is a line with its sequence number and length.

To read just the first few lines of a message, use the TOP command. This takes two parameters, a message number and a number of lines, and returns the full header of the message plus however many lines you asked for. Many virus messages usually have the nasty attachment's filename visible within the first 20 lines, so TOP 1 20 may identify them.

Note the final full stop on the response, but the +OK line again should include the length.

To see just the header and nothing from the body, use TOP 1 0. To view a message in its entirety, use the RETR (for retrieve) command; RETR 1

To delete a message, use the DELE (for delete) command; DELE 1

When you are done, use the QUIT command; QUIT

Note that most POP3 servers will time you out after a period of inactivity.