POP3 Commands Cheat Sheet: Quick Reference
Post Office Protocol version 3 (POP3) is a standard mail protocol used by email clients to retrieve messages from a mail server. While most modern email clients handle the POP3 interaction behind the scenes, understanding the underlying commands can be invaluable for troubleshooting, scripting, and developing custom email applications. This cheat sheet provides a detailed description of common POP3 commands, including their syntax, functionality, and potential responses from the server.
Connection and Authorization:
-
USER
: Initiates the authentication process. The server expects the client to send the username associated with the mailbox. - +OK: Server acknowledges the username and awaits the password.
- -ERR: Invalid username or other server-side error.
-
PASS
: Provides the password for the specified username. - +OK: Successful authentication. The client can now issue other POP3 commands.
- -ERR: Incorrect password, account locked, or other authentication failure.
-
APOP
<digest>
is the MD5 hash of the timestamp provided by the server during the initial greeting and the user’s password.- +OK: Successful APOP authentication.
- -ERR: Authentication failure.
-
QUIT: Terminates the POP3 session. Any changes made during the session (e.g., message deletion) are committed.
- +OK: Server acknowledges the quit command and closes the connection.
Mailbox Status and Retrieval:
-
STAT: Retrieves mailbox statistics, including the number of messages and the total size of the mailbox in bytes.
- +OK
- +OK
-
LIST [
] : Lists the message numbers and their respective sizes. If a message number is specified, it returns the size of that specific message.- +OK: Followed by a multi-line response listing message numbers and sizes (one per line). Ends with a
.
. - +OK
: If a specific message number is provided. - -ERR: Invalid message number.
- +OK: Followed by a multi-line response listing message numbers and sizes (one per line). Ends with a
-
RETR
: Retrieves the full content of the specified message. - +OK: Followed by the message content, ending with a
.
. - -ERR: Invalid message number or other retrieval error.
- +OK: Followed by the message content, ending with a
-
TOP
- +OK: Followed by the header and the specified lines of the body, ending with a
.
. - -ERR: Invalid message number or line count.
- +OK: Followed by the header and the specified lines of the body, ending with a
-
UIDL [
] : Returns a unique identifier for each message. If a message number is provided, returns the UIDL for that specific message. These identifiers persist across sessions, even if messages are deleted and re-numbered.- +OK: Followed by a multi-line response listing message numbers and their UIDs (one per line). Ends with a
.
. - +OK
: If a specific message number is provided.
- +OK: Followed by a multi-line response listing message numbers and their UIDs (one per line). Ends with a
Message Manipulation:
-
DELE
: Marks the specified message for deletion. The actual deletion occurs when the session is terminated with the QUIT
command.- +OK: Message marked for deletion.
- -ERR: Invalid message number.
-
RSET: Resets the session. Any messages marked for deletion are unmarked.
- +OK: Session reset.
-
NOOP: A no-operation command. Useful for keeping the connection alive.
- +OK: Server acknowledges the NOOP command.
Server Responses and Error Codes:
POP3 servers respond to commands with a status indicator followed by additional information. The status indicator can be either +OK
(success) or -ERR
(failure). Error messages can provide more specific details about the failure, but the exact format varies between servers. Common error scenarios include:
- Invalid username or password: Indicates an incorrect login attempt.
- Mailbox locked: The mailbox might be temporarily inaccessible due to maintenance or other reasons.
- Invalid message number: The specified message number does not exist.
- Server error: A general error on the server-side.
Example POP3 Session:
S: +OK POP3 server ready <[email protected]>
C: APOP mrc 1323393993
S: +OK mrc's maildrop has 2 messages (320 octets)
C: STAT
S: +OK 2 320
C: LIST
S: +OK
S: 1 120
S: 2 200
S: .
C: RETR 1
S: +OK 120 octets
S: <message content>
S: .
C: DELE 1
S: +OK
C: QUIT
S: +OK POP3 server signing off
Practical Considerations:
-
Security: While POP3 supports basic authentication, it’s generally recommended to use SSL/TLS encryption to protect credentials and message content during transmission. This is often referred to as POP3S and typically uses port 995.
-
Message Retention: By default, POP3 removes messages from the server after they are downloaded. This can be problematic if you access your mailbox from multiple devices. Some email clients offer an option to leave messages on the server for a specified period.
Looking Ahead:
While POP3 remains a widely used protocol, IMAP (Internet Message Access Protocol) offers several advantages, including the ability to synchronize messages across multiple devices and manage folders on the server. Consider exploring IMAP if these features are important to you.
This detailed overview of POP3 commands provides a solid foundation for understanding and interacting with email servers. Whether you’re troubleshooting email issues, automating tasks, or developing email applications, this cheat sheet will serve as a valuable quick reference. Remember to consult your specific email server’s documentation for any implementation-specific details or variations.