Understanding POP3: Email Retrieval Protocol
POP3: Post Office Protocol
POP3 (Post Office Protocol version 3) is an application protocol used to retrieve emails from a remote mail server. This document provides a complete specification of the protocol, considering each of these features:
- Services offered by the protocol.
- Assumptions of the environment, i.e., the context or setting in which this protocol works.
- Vocabulary, the set of messages that use the protocol to indicate their status.
- Coding, the format used for sending the messages used by the protocol.
- Rules of procedure, protocol standards used to exchange messages consistently and orderly.
Prior to the analysis of the protocol in particular, we will conduct a review of the fundamental concepts that form an email, the elements that compose it, the protocols used, etc.
Brief Review of Email
What is the Email Service?
Email is based on the creation and transmission of messages between users on the network without being connected simultaneously. It is the most used Internet service.
In general, email features are:
- It is an interpersonal messaging system with a sender and one or more recipients; the sender may be included among the recipients.
- It is interactive, i.e., an immediate reply message is not expected.
- It is non-intrusive, i.e., one can read when one wants. It allows the user to develop its content.
MIME Types
MIME types (Multipurpose Internet Mail Extensions) are a series of specifications that allow the exchange through the Internet of all kinds of files (plain text, HTML, audio, video, etc.) transparently to the user. Generally, they are used to format non-ASCII messages so they can be sent over the Internet.
There are predefined MIME types such as GIF, JPEG, or Postscript, but it is possible to define your own MIME types.
The purpose of MIME is to allow any type of message (text, images, voice, data, binary, etc.) to be sent via SMTP simply and transparently to the user.
Elements of Email Service
MTA (Mail Transfer Agent)
It is the agent responsible for transferring email messages between machines using the SMTP protocol. On their journey from origin to final destination, a message may go through several MTAs transparently to the user. Its functions are:
- It is responsible for routing mail between the different systems.
- It is what is known as a mail server, also a courier or mail delivery agent.
- It handles the routing of outgoing mail and awaits the arrival of incoming mail from the Internet.
MDA (Mail Delivery Agent)
It is distinguished by the following:
- Its function is to copy the messages from the mail transfer agent (MTA) or mail server to the user’s mailbox.
- The MDA agent does not transport messages between systems nor does it work as an interface for the user.
- POP and IMAP email clients can be regarded as MDA agents.
Mail Server
This application allows sending email messages between users regardless of the operating system that these users use. It is responsible for mail routing between different systems.
Mail Client
These applications allow users to connect with their corresponding mailboxes and carry out the download of emails using the POP3 and IMAP protocols, as well as compose new messages, organize messages into folders, maintain an email address book, and so on.
MUA (Mail User Agent) is the program that the user executes to read incoming mail or send messages. Its main features are:
- It is the user interface that lets you edit, compose, and deliver local mail.
- These are called mail clients.
- Examples: Outlook Express, Thunderbird.
Structure of Emails
Emails have a structure that facilitates user identification of the receiver and the source of the message (sender), to detect errors in transmission, and so on.
The fields contained in the header are:
- Sender (FROM): Name and address of the user sending the message.
- Recipient (TO): Name and address of the recipient.
- Recipient copy (CC, carbon copy): Name and address of the recipient of the copy of the message.
- Bcc recipient (BCC, blind carbon copy): Name and address of the recipient of the Bcc of the message that none of the senders know.
- Reply (REPLY-TO): Indicates the email to the sender that the user wants to be answered. This field is optional and useful when the user has several email accounts but, for personal reasons, prefers to receive answers on a particular account.
Email Protocols
These are what allow machines that run on different operating systems and use various mail clients to communicate and transfer email.
SMTP Protocol
SMTP, or Simple Mail Transfer Protocol, is the Internet standard for exchanging electronic mail.
The function of the SMTP protocol is the transport of outgoing mail from the sender’s user machine to the server that stores messages for intended users. For this, the user writes the sender of the mail and sends it to their mail server. From the sender’s mail server, the message will be forwarded to the recipient’s mail server. Finally, the recipient downloads the mail from their mailbox on the local machine with the POP3 protocol or consultation, via the web, using the IMAP protocol.
SMTP uses port 25 to communicate, and the protocol is a set of commands and responses between the transmitter and receiver.
POP
The main advantage of this protocol is that folders, messages, etc., are stored on our computer, which allows us to read incoming mail without being connected to the network. Furthermore, reading the messages and downloading them to your computer frees up space in our mailbox, making it less likely that our mailbox will inadvertently fill up and prevent us from receiving more messages. It is the most widespread (almost all mail programs support it) and is ideal for always connecting from the same computer.
IMAP Protocol
The main difference from the previous protocol is that both messages and folders are saved in the mailbox and on the computer. This may seem inconvenient, but it is useful for connecting from a shared computer, as messages cannot be read by other people and do not stay on the PC. As well, if we are not able to always connect from the same computer, we will always have access to all our messages.
Specifying the POP3 Protocol
Service
Post Office Protocol version 3 (versions 1 and 2 are obsolete) is a protocol that is at level 7 of the OSI stack (application layer). It is designed to receive mail from a remote server but not send new messages (the latter uses SMTP).
POP3 uses TCP as the transport protocol, thus ensuring all the services it offers, such as error control, flow, order of arrival, and so on. Furthermore, the use of TCP means that POP3 is a connection-oriented protocol. Typically, a POP3 client often uses port 110 to connect to the mail server.
Like many other old protocols, POP3 does not use any encryption or secure authentication mechanism. Therefore, there are many variants that modify this behavior, and among the most common is to combine a POP3 socket over SSL to avoid sending sensitive data (such as personal emails or passwords) in plaintext over the network.
Assumptions about the Environment
The work environment is usually constant for POP3: a client, usually with specific software (a mail client), connects to a remote server using a TCP socket. If the channel introduces errors, produces losses, crashes, or reorders messages, TCP handles solving these problems.
Vocabulary
A POP3 client can send any of these messages to perform the desired operation:
- USER <name> Username (Only done once).
- PASS <password> Key sent by the user to the server.
- STAT Gives the number of messages that are not deleted in the mailbox and their total length.
- LIST Displays all the messages that are not deleted with their length.
- RETR <number> Request to send the message specifying the number (not deleted from the mailbox).
- NOOP Does nothing, just returns a message +OK.
- TOP <number> <lines> Sample header and required number of lines of the message specifying the number.
- DELE <number> Deletes a message specifying the number.
- RSET Recovers deleted messages (in the current connection).
- UIDL <number> Returns a string identifying the message persistently across sessions. If not specified <number>, it returns a list of message numbers and message identifier strings that are not deleted.
- QUIT Exit.
For its part, the server responds with two types of messages:
- +OK The requested operation was successful.
- -ERR The operation failed.
These response messages are often accompanied by text that specifies the status of the server or adds information about the error that occurred.
Consolidation
Messages on POP3, as in other protocols such as HTTP or FTP, are sent as plain ASCII text. This allows an experienced user to use a Telnet client to connect to a remote server and test the performance of the protocol.
Rules of Procedure
Informally, all POP3 messages sent by the client are answered with only two types of messages: +OK or -ERR.
For example, if the message sent does not correspond to any of those in the “vocabulary”, the server will usually answer with a “-ERR Unrecognized command”. If, instead, the command is valid, but it is not possible to carry it out because the client has not authenticated, it can answer with “-ERR Please login with USER and PASS first.”