Post Office Protocol version 3 (POP3) is a standard mail protocol used to receive emails from a remote server to a local email client.
POP3 begins when the user agent (the client) opens a TCP connection to the mail server (the server) on port 110.
当TCP连接建立好之后，POP3 progresses through 3 phases:
the user agent sends a username and a password (in the clear,明文）to authenticate the server.
- user <username>
- pass <password>
为了搞清楚这两个命令，我们建议你最好使用Telnet直接登录到a POP3 server, using port 110, and issue these commands.
假定 mailServer 是你的邮件服务器的名称，You will see something like:
telnet mailServer 110
+OK POP3 server ready
+OK user successfully logged on
If you misspell a command, the POP3 server will reply will an -ERR message.
the user agent retrieves messages; also during the phase, the user agent can mark messages for deletion, remove deletion marks and obtain mail statistics.
In a POP3 transaction, the user agent issues commands, and the server responds to each command with a reply. 有两种可能的回复：
- +OK (sometimes followed by server-to-client data),used by the server to indicate that the previous command was fine.
- -ERR, used by the server to indicate that something was wrong with the previous command.
A user agent using POP3 can often be configured (by the user) to “download and delete” or “download and keep”. The sequence of commands issued by a POP3 user agent depends on which of these two modes the user agent is operating in.
- In the download-and-delete mode, the user agent will issue the
As an example, suppose the user has 2 messages in his or her mailbox.
In the dialogue below, C: (standing for client) is the user agent and S: (standing for server) is the mail server. The transaction will look something like:
S: 1 498
S: 2 912
C: retr 1
S: (blah blah ...)
C: dele 1
C: retr 2
S: (blah blah ...)
C: dele 2
S: +OK POP3 server signing off
The user agent first asks the mail server to list the size of each of the stored messages.
The user agent then retrieves and deletes each message from the server.
这些命令的语法is defined in RFC 1939.
After processing the
quit command, the POP3 server enters the update phase and removes messages 1 and 2 from the mailbox.
A problem with this download-and-delete mode is that the recipient, Bob可能是一个到处跑的产品经理, may want to access his mail messages from multiple machines. 举个例子， his office PC, his home PC, and his portable computer.
The download-and-delete mode partitions Bob’s mail messages over these 3 machines: In particular, If Bob first reads a message on his office PC, he will not be able to reread the message from his portable PC at home later in the evening.
In the download and keep mode, the user agent leaves the messages on the mail server after downloading them. In this case, Bob can reread messages from different machines; he can access a message from work and access it again later in the week from home.
the update phase occurs after the client has issued the
quit command, ending the POP3 session; at this time, the mail server deletes the messages that were marked for deletion.
During a POP3 session between a user agent and the mail server, the POP3 server maintains some state information; In particular, it keeps track of which user messages have been marked deleted.
However, the POP3 server does not carry state information across POP3 sessions. The lack of state information across sessions greatly simplifies the implementation of a POP3 server.