The Simple Mail Transfer Protocol (SMTP) is a standard that enables users to send email messages over a network. SMTP is platform agnostic and specializes in sending message data to a pre-configured mail server—after which protocols such as IMAP and POP deliver those messages to the end user. Resultantly, SMTP is considered a "push" protocol since it doesn't cover the last mile of that journey.
SMTP received its RFC certification in 1982 and is an application layer (Layer 7) protocol within the OSI model. It's connection-oriented, text-based, and sends emails between backend servers without direct client interaction. The protocol is known for being reliable yet somewhat slow in many cases, as misconfiguration and multiple network roundtrips can undermine performance. As a result, many external, API-based email services have arisen to boost performance and scalability.
How does the Simple Mail Transfer Protocol (SMTP) work?
First, SMTP is used for server to server communication—not server to client. It's designed to work seamlessly with IMAP and POP to deliver messages from origin to destination. However, forming a connection between client and server still remains important, especially so the protocol remains client-aware.
Just like UDP sends datagrams across the network, SMTP initially packages information into "envelopes." The outgoing mail server uses envelopes to learn where the message is from and where it's headed. However, this information isn't attached to the message header or body—it's automatically generated directly from data in the message object fields. SMTP uses the TCP protocol to carry this data onward.
A typical SMTP transaction occurs like this:
A TCP handshake connects the client and server before a specialized SMTP command—such as HELO/EHLO—kicks off the sending process.
The client sends commands and the message contents to the mail server. This can include a message header, a body, and any optional components to contextualize the request. A mail submission agent (MSA) receives these emails from the email client itself (Gmail, Yahoo!, etc.).
The mail transfer agent (MTA) searches for the domain of the recipient's email address, then promptly uses DNS to locate their IP address if that domain differs from the sender's.
The data transfer occurs and the message is ultimately delivered via a mail delivery agent (MDA). Once the message has been completely transmitted, the SMTP connection closes (per the client's instructions). A new connection is needed to send additional messages once this happens.
Like any networking, SMTP relies on a number of ports to communicate:
Port 25 – This was the first port reserved for SMTP communication and is used most commonly. However, this port is a common spam target, which is why many firewalls block it.
Port 587 – This is now the default port for SMTP over TLS. It's used to prevent interference with traditional communications over port 25.
Port 465 – Once used to facilitate SMTP communication over SSL, this port is used less frequently due to the introduction of TLS and evolving practices. The port is IANA designated, however, and is therefore used (and maintained) to support legacy email systems.
Port 2525 – Some providers use this as a backup port for SMTP in case others are blocked. It supports TLS and is also a good overflow option when other ports are congested.
Finally, SMTP comes in a couple of different "flavors": Extended SMTP (ESMTP) and SMTPS. The former offers more sending and attachment flexibility and supports TLS, while the latter leverages the older SSL or TLS for security purposes.
Does HAProxy support SMTP?
Yes! HAProxy Enterprise users can leverage SMTP mailers to alert them to server status changes. This is handy for monitoring server health and overall performance for your HAProxy Enterprise clusters. You can also add health checks for both SMTP and ESMTP services.
To learn more about SMTP support in HAProxy, check out our SMTP health checks documentation.