POP (the standard version is POP3, described by RFC 1725) is the way that most Web clients
retrieve email from Internet mail servers. Like most Internet protocols, it is
command-line-based, that is, all operations are performed by building text commands and sending
them to the server. So it's easy to simulate being a client by using telnet to connect
to the server, and it's easy to write a client to do specialized email-related
tasks, too. I've written a POP3 client for AOLserver which is the core of an autoresponder
engine; it took me about six hours.
The POP3 server listens on port 110. If you telnet to a POP3 server on port 110, you will see
something like this:
+OK POP3 cs.indiana.edu v4.38 server ready
As you can see, the line begins with the status indicator +OK . Each response from
a POP3 server begins with either +OK or -ERR . Cool, huh?
At the beginning of the session, you're in login mode. The only commands available at this point
are USER, PASS, and QUIT. Each of those is obvious. Additionally, some POP3 servers support
an encrypted login feature APOP.
Once you've logged into the server using the USER and PASS commands, you can work with the
mailbox. The commands for doing this are as follows (with a couple of omissions):
STAT |
STAT simply responds with a single line consisting of two numbers: the number of messages
in the box and the total size of those messages in bytes. It's useful for human beings, but
less so for automatic clients, which are likely to jump straight to the LIST command. |
LIST |
LIST lists the contents of the mailbox, naturally enough. It does so by using the standard
POP3 multi-line response format. Here's an example:
LIST
+OK Mailbox contents follow
1 7774
2 513
3 10493
.
The terminating line is a period on a line by itself, which is pretty standard for mail protocols
in general. Each line consists of the mail message number (if you delete one, it won't appear in
the list, so don't fall into the trap that the numbers are sequential and can thus be ignored!) followed
by the size of the message in bytes.
LIST plus a message number will simply act like STAT for that message.
|
RETR msg |
RETR retrieves a message. Use the message number from LIST. Note that you'll receive the
true text of the message, headers followed by a blank line followed by the body, followed by a
period on a line by itself. If the body actually contains a period on a line by itself, the
mail server will already have doubled that period. So your client needs to undouble it.
|
DELE msg |
DELE deletes a message. It won't actually be deleted until you QUIT the session, and you can
undelete everything you've deleted (in case of a mistake) by using RSET.
|
TOP msg n |
TOP is actually an optional command, but most servers support it now. It returns the headers
of message msg plus n lines of the body. If n is zero, of course, you just
get the headers, which is nice for doing filtering without having to get the entire message.
|
QUIT |
QUIT terminates the session and deletes any messages marked with DELE.
|
And that's really all you need to know to use POP3. That wasn't so hard, was it?
|