POP3 Described
POP3 is a protocol used by a client to access and download messages that are held temporarily by the server. You might recall from the Email Short History that POP was developed because SMTP lacked a method of queuing messages on the recipient's mail server. POP provided a system for queuing messages and allowing the user to periodically log in to the mail server, download messages, and log out, thereby greatly reducing the strain on both mail servers and user machines to maintain a constant and resident connection.
A POP session is made up of the client and server exchanging commands and responses, lock-step. The client and mail server continue to exchange commands and responses until the session is terminated. This session can be broken down into three states: authorization state, transaction state, and update state.
POP3 Authorization State
A POP3 session begins with the server (normally) listening for connections on port 110. The authorization state begins when a client makes a TCP connection on port 110 and the server issues a greeting. The client must issue the USER command followed by its user identification. If the server responds with a positive success indicator ("+OK"), the user may issue the PASS command followed by its password. If the server again issues a positive success indicator ("+OK") the server acquires the client's associated maildrop located on the server and the session moves into the transaction state. An example of this follows:
Server: <wait for connection on TCP port 110> Client: <open connection> Server: +OK dewey POP3 server ready Client: USER mrose Server: +OK mrose Client: PASS secret Server: +OK mrose's maildrop has 2 messages (320 octets)
At this point the user is logged into the mail server and the mail server has acquired the user's associated maildrop. The session has now entered the transaction state. Using PowerTCP Mail for .NET, the Login method accomplishes all of this.
POP3 Transaction State
The transaction state consists of the client issuing one of several commands and the server responding either positively or negatively. These commands are mainly used to acquire information about the mail located on the mail server, or to retrieve mail from the mail server. Some possible commands are:
- STAT- The server will return the total messages and total size.
- LIST [msg]- If no argument is given, the server will return a multi-line response enumerating each message and its statistics. If an argument is given, the server will simply return the statistics for the message specified by msg or an error message if the message does not exist.
- RETR msg- The server will return with a multi-line response of the content of the message specified by msg or an error if the message does not exist.
- DELE msg- If the message specified by the argument msg is valid, the POP3 server will mark the message for deletion and return a positive response. If the message does not exist or has already been marked for deletion, the server will return an error.
- NOOP- The server will simply respond to this command with a positive response.
- LAST- The server will return the number of the highest accessed message.
- RSET- Any messages marked for deletion are unmarked.
- QUIT- Ends the POP3 session, the server will enter the update state.
The transaction state can take many forms but the following shows a possible dialogue between client and server.
Client: STAT Server: +OK 2 320 Client: LIST Server: +OK 2 messages (320 octets) Server: 1 120 Server: 2 200 Server: . Client: RETR 1 Server: +OK 120 octets Server: < the POP3 server sends message 1 > Server: . Client: DELE 1 Server: +OK message 1 deleted Client: RETR 2 Server: +OK 200 octets Server: < the POP3 server sends message 2 > Server: . Client: DELE 2 Server: +OK message 2 deleted Client: QUIT
Once the QUIT command has been issued, the transaction state is over and the session now moves into the update state.
POP3 Update State
In the update state the server will delete all messages marked for deletion, release the resources associated with the client's maildrop, and close the TCP connection.
For more detailed information about the POP3 protocol refer to RFC 1939.