The flip side to sending mail is, of course, receiving it. This is done using the POP or Post Office Protocol. It is a very similar "dialog" process to SMTP.
A POP3 session progresses through a number of states during its lifetime. Once the TCP connection has been opened and the POP3 server has sent the greeting, the session enters the AUTHORIZATION state. In this state, the client must identify itself to the POP3 server. Once the client has successfully done this, the server acquires resources associated with the client's maildrop, and the session enters the TRANSACTION state. In this state, the client requests actions on the part of the POP3 server. When the client has issued the QUIT command, the session enters the UPDATE state. In this state, the POP3 server releases any resources acquired during the TRANSACTION state and says goodbye. The TCP connection is then closed.
A POP3 server MAY have an inactivity autologout timer. Such a timer MUST be of at least 10 minutes' duration. The receipt of any command from the client during that interval should suffice to reset the autologout timer. When the timer expires, the session does NOT enter the UPDATE state-the server should close the TCP connection without removing any messages or sending any response to the client.
Once the TCP connection has been opened by a POP3 client, the POP3 server issues a one line greeting. This can be any string terminated by CRLF. An example might be:
S: +OK POP3 server ready
Note that this greeting is a POP3 reply. The POP3 server should always give a positive response as the greeting.
The POP3 session is now in the AUTHORIZATION state. The client must now identify and authenticate itself to the POP3 server. Two possible mechanisms for doing this are described in this document, the USER and PASS command combination and the APOP command. The APOP command is described later in this document.
To authenticate using the USER and PASS command combination, the client must first issue the USER command. If the POP3 server responds with a positive status indicator ("+OK"), then the client may issue either the PASS command to complete the authentication, or the QUIT command to terminate the POP3 session. If the POP3 server responds with a negative status indicator ("-ERR") to the USER command, then the client may either issue a new authentication command or may issue the QUIT command.
When the client issues the PASS command, the POP3 server uses the argument pair from the USER and PASS commands to determine if the client should be given access to the appropriate maildrop.
Once the POP3 server has determined through the use of any authentication command that the client should be given access to the appropriate maildrop, the POP3 server then acquires an exclusive- access lock on the maildrop, as necessary to prevent messages from being modified or removed before the session enters the UPDATE state. If the lock is successfully acquired, the POP3 server responds with a positive status indicator. The POP3 session now enters the TRANSACTION state, with no messages marked as deleted. If the the maildrop cannot be opened for some reason (for example, a lock can not be acquired, the client is denied access to the appropriate maildrop, or the maildrop cannot be parsed), the POP3 server responds with a negative status indicator. (If a lock was acquired but the POP3 server intends to respond with a negative status indicator, the POP3 server must release the lock prior to rejecting the command.) After returning a negative status indicator, the server may close the connection. If the server does not close the connection, the client may either issue a new authentication command and start again, or the client may issue the QUIT command.
After the POP3 server has opened the maildrop, it assigns a message- number to each message, and notes the size of each message in octets. The first message in the maildrop is assigned a message-number of "1", the second is assigned "2", and so on, so that the n'th message in a maildrop is assigned a message-number of "n". In POP3 commands and responses, all message-number's and message sizes are expressed in base-10 (i.e., decimal).
Minimal POP3 Commands:
The folowing commands are essential and are valid in the AUTHORIZATION state:
The folowing commands are essential and are valid in the TRANSACTION state:
The folowing commands are essential and are valid in the UPDATE state:
The following are optional POP3 Commands:
Note: that if the number of lines requested by the POP3 client is greater than than the number of lines in the body, then the POP3 server sends the entire message.
The following are the POP Replies:
Note that with the exception of the STAT, LIST, and UIDL commands, the reply given by the POP3 server to any command is significant only to "+OK" and "-ERR". Any text occurring after this reply may be ignored by the client.
Sample POP Session
< <wait for connection on TCP port 110> > open connection < +OK POP3 server ready <sentinel.cs.cf.ac.uk> > APOP mrose c4c9334bac560ecc979e58001b3e22fb < +OK mrose's maildrop has 2 messages (320 octets) > STAT < +OK 2 320 > LIST < +OK 2 messages (320 octets) < 1 120 < 2 200 < . > RETR 1 < +OK 120 octets < The POP3 server sends message 1 < . > DELE 1 < +OK message 1 deleted > RETR 2 < +OK 200 octets < <the POP3 server sends message 2> < . > DELE 2 < +OK message 2 deleted > QUIT < +OK dewey POP3 server signing off (maildrop empty) < close connection < wait for next connection...