Although POP3
is becoming an antiquated protocol to connect to a mail server, it is quite useful to test if a mail account is set up properly.
POP3 Commands
Normally I just try to login and stop there, but there are some more commands in your POP3-toolbox.
Command | Description |
---|---|
USER <username> |
Login to the account <username> (required). |
PASS <password> |
Login with the password <password> (required, plaintext). |
QUIT |
Close the connection. |
STAT |
Shows the number of messages and the total size of the mailbox. |
LIST [message] |
Displays a list of messages with their numbers and respective sizes, or a single message number with its size. |
UIDL [message] |
Displays a list of messages with unique identifiers for each message. |
RETR <message> |
Display the header and body content of the specified message. |
TOP <message> <lines> |
Display the header of the specified message. If <lines> is set it will also show this number of lines from the body content. |
DELE <message> |
Mark the specified message for deletion. |
RSET |
Clears any delete flags set by the DELE command. |
NOOP |
Does nothing, simply used to avoid server timeouts. |
POP3 Replies
There are just 2 replies possible with POP3: +OK
and -ERR
, meaning, you guessed it, that your command was successful or that it failed.
It is possible that these replies are followed by some more information to show the result of a command or the reason of the error.
Connect to the server
We’re going to use telnet
to connect to the mail server.
$ telnet example.com 110
And we’re greeted by a welcome message:
Connected to example.com.
Escape character is '^]'.
+OK POP3 server ready.
The server is waiting for our first command. So let’s try to login. First we need to provider our username:
USER <username>
+OK
Followed by our password (Note: it will be shown as plaintext!):
PASS <password>
+OK Logged in.
Success, we’re in!
Working with messages
List
To display a list of the messages in our mailbox:
LIST
+OK 5 messages:
1 3375
2 3622
3 3606
4 3630
5 3834
This will tell you how many messages there are and will also give a list with on each line a message number and the message size in bytes (you gotta love those old’n days where people were concerned about disk space).
The STAT
command will also tell you the number of messages, plus the total size of the mailbox:
STAT
+OK 5 18067
Read
You have 2 similar commands to your disposal for reading messages: TOP
and RETR
. Both commands will show you the content of a message and therefore need a message number. But TOP
also accepts a second parameter so you can specify the number of lines of body content to show (it will always show the headers). When no lines are specified it is assumed to be 0.
TOP 1
+OK
Return-Path: <sender@example.com>
Delivered-To: info@example.com
Received: from localhost (localhost [127.0.0.1])
by example.com (Postfix) with ESMTP id 10315142CF8
for <info@example.com>; Mon, 23 Feb 2015 13:19:37 +0100 (CET)
Date: Mon, 23 Feb 2015 04:19:35 -0700
From: <sender@example.com>
To: info@example.com
Message-ID: <78AF5C73C263AF24BA943DEEBB142316@example.com>
Subject: Just a test message
Delete
To delete a message we can use the DELE
command:
DELE 1
+OK Marked to be deleted.
If the message does not exist or has been deleted, you will see the following error messages:
DELE 1
-ERR Message is deleted.
DELE 9999
-ERR There's no message 9999.
The message is not deleted instantly, this will only happen when you close the connection. To recover the deleted message before you log out, you can use RSET
:
RSET
+OK
This will clear any delete flags that have been set.
Quit
To close the connection and actually delete any messages marked for deletion:
QUIT
+OK Logging out.