The Simple Mail Transfer Protocol (SMTP) is a technical standard designed for the transmission of electronic mail (email) over a network. Operating as one of many networking protocols, SMTP facilitates the exchange of data between computers and servers, irrespective of the underlying hardware or software. Much like how a standardized addressing format on an envelope enables efficient postal service operations, SMTP standardizes the process through which email travels from a sender to a recipient, playing a pivotal role in enabling widespread email delivery.

It's crucial to note that SMTP is a mail delivery protocol, not a mail retrieval protocol. Drawing an analogy to traditional mail services, where the postal service delivers mail to a mailbox but the recipient must retrieve it, SMTP delivers an email to an email provider's mail server. Subsequent protocols are then employed to retrieve the email from the mail server, allowing the recipient to access and read the message. In essence, SMTP serves as the mechanism for transporting emails to their designated mail servers, forming an integral part of the overall email communication infrastructure.

How does SMTP work?

SMTP (Simple Mail Transfer Protocol) follows a predefined process for exchanging data between an email client and a mail server. The interaction between the email client, where users access and send emails, and the mail server, a specialized computer handling email transmission, can be summarized in the following steps:

  1. SMTP Connection Opened: The process begins with the opening of a TCP (Transmission Control Protocol) connection between the email client and the mail server. The email client initiates the email sending process with a specialized "Hello" command (HELO or EHLO).
  2. Email Data Transferred: The client then sends a series of commands to the server, accompanied by the actual content of the email. This includes the email header (containing destination and subject line), the email body, and any additional components.
  3. Mail Transfer Agent (MTA): The server runs a program known as a Mail Transfer Agent (MTA). The MTA checks the domain of the recipient's email address. If it differs from the sender's domain, the MTA queries the Domain Name System (DNS) to find the recipient's IP address, similar to a post office looking up a mail recipient's zip code.
  4. Connection Closed: Upon completion of data transmission, the client notifies the server, and the server closes the connection. At this point, the server won't receive additional email data unless the client initiates a new SMTP connection.

It's important to note that the initial email server may not be the final destination for the email. After receiving the email, the server repeats the SMTP connection process with another mail server. This relay continues until the email reaches the recipient's inbox on a mail server controlled by the recipient's email provider.

Comparatively, this process resembles the way a physical piece of mail travels from sender to recipient. Similar to a mail carrier not taking a letter directly to its recipient, emails traverse from server to server via SMTP until they reach the recipient's inbox.

What is an SMTP envelope?

The SMTP "envelope" refers to the set of information that the email client transmits to the mail server regarding the origin and destination of the email. This envelope is a separate entity from the email header and body, and its details are not visible to the email recipient.

In essence, the SMTP envelope contains essential addressing and routing information required for the proper transmission of the email. It serves as a means of instructing the mail server on how to handle the email, specifying the sender's address, recipient addresses, and other pertinent details necessary for successful delivery. Unlike the email header and body, which are visible to the email recipient, the SMTP envelope is an internal component of the email communication process, facilitating the behind-the-scenes routing and delivery of the message.

What are SMTP commands?

SMTP commands are predefined text-based instructions that guide a client or server on what actions to take and how to process accompanying data. Think of these commands as buttons that the client can press to prompt the server to handle data appropriately. Here are some essential SMTP commands:

  1. HELO/EHLO: HELO: Initiates the SMTP connection between the client and server, essentially saying "Hello."EHLO: A specialized version of the "Hello" command used for extended features in certain types of SMTP connections.
  2. MAIL FROM: Specifies the sender of the email. For instance, if Alice is sending an email to her friend Bob, the client might send: MAIL FROM:<emaildojo@emaildojo.io>.
  3. RCPT TO: Lists the recipients of the email. This command can be sent multiple times for emails with multiple recipients. Using the example above, Alice's email client might send: RCPT TO:<raj@emaildojo.io>.
  4. RSET: Resets the connection, removing all previously transferred information without closing the SMTP connection. RSET is used if the client sent incorrect information.
  5. QUIT: Ends the connection, indicating that the communication session is complete.
  6. DATA: Precedes the content of the email. The actual email content is encapsulated between the DATA command and the end of the data section. For example:
DATA
Date: Mon, 4 April 2022
From: emaildojo <emaildojo@emaildojo.io>
Subject: Eggs Benedict Casserole
To: Raj <raj@example.com>

Hi Raj,
I will bring the eggs benedict casserole recipe on Friday.
-Team emaildojo.

These commands form the basis of the communication protocol between an email client and a mail server, facilitating the proper exchange of information for the transmission of emails.

What is an SMTP server?

An SMTP server is a mail server designed to send and receive emails using the Simple Mail Transfer Protocol (SMTP). When users send emails, their email clients connect directly to the SMTP server of their email provider to initiate the email transmission process. The SMTP server is a crucial component in the email infrastructure and performs several functions through various software programs:

  1. Mail Submission Agent (MSA): The MSA is responsible for receiving emails from the email client. It acts as the initial point of contact for email submission.
  2. Mail Transfer Agent (MTA): The MTA handles the transfer of emails to the next server in the delivery chain. It may perform additional tasks, such as querying the Domain Name System (DNS) to determine the mail exchange (MX) DNS record of the recipient domain if required. This ensures proper routing to the destination.
  3. Mail Delivery Agent (MDA): The MDA is responsible for receiving emails from MTAs and storing them in the recipient's email inbox. It acts as the final destination for the delivered emails.

What port does SMTP use?

In networking, a port serves as the virtual point where network data is received, similar to the apartment number in the address of a piece of mail. Ports assist computers in sorting networking data to the correct applications, and network security measures, such as firewalls, may block unnecessary ports to prevent the transmission of malicious data.

Historically, SMTP primarily utilized port 25. However, in contemporary settings, SMTP can also operate on ports 465, 587, and 2525:

  1. Port 25: Traditionally used for connections between SMTP servers. Firewalls in end-user networks often block this port due to attempts by spammers to abuse it for sending large volumes of spam.
  2. Port 465: Initially designated for SMTP with Secure Sockets Layer (SSL) encryption. However, SSL has been replaced by Transport Layer Security (TLS), and modern email systems do not use this port. It may still be found in legacy (outdated) systems.
  3. Port 587: The current default port for email submission. SMTP communications via this port utilize TLS encryption, providing a more secure transmission channel.
  4. Port 2525: Not officially associated with SMTP, but some email services offer SMTP delivery over this port as an alternative in case the previously mentioned ports (25, 465, 587) are blocked.

SMTP vs. IMAP and POP

The Internet Message Access Protocol (IMAP) and Post Office Protocol (POP) are used to retrieve email from the final mail server in the chain. While SMTP "pushes" email to a mail server, IMAP and POP "pull" it to the user's application.

What is Extended SMTP (ESMTP)?

Extended Simple Mail Transfer Protocol (ESMTP) expands upon the original SMTP capabilities, allowing features like sending email attachments and using TLS. Almost all email clients and services use ESMTP, not basic SMTP. ESMTP includes additional commands, such as "EHLO," an "extended hello" message enabling the use of ESMTP at the start of the connection.