Emails are the most common yet powerful way of communication. The number of e-mails sent and received globally is increasing each year. In 2021, there were an estimated 319.6 billion e-mails sent and received daily globally around the world and This figure is projected to increase to 376.4 billion daily e-mails by 2025. Have you ever wondered how your emails go from you to your recipients?
Just opposite to how simple and easy the email sending process is, there’s a complex process behind the scenes to get your emails delivered. The most common protocol for sending emails is SMTP.
What is SMTP?
SMTP, which stands for Simple Mail Transfer Protocol, is an email protocol used by mail servers for sending email messages from sender’s email account to receiver’s email account via the internet.
Email protocols are a standard method or set of rules for information exchange, and SMTP is one of the most common ones alongside Post Office Protocol 3 (POP3) and Internet Message Access Protocol (IMAP). POP and IMAP protocols are for sending and receiving emails but SMTP is the only dedicated protocol for sending emails.
What is an SMTP server?
An SMTP server is a computer or an application running SMTP that is responsible for sending emails. An SMTP server receives emails from the email client and passes them to another SMTP server and relays them to the incoming mail server. Specifically, an SMTP server handles the sending, receiving, and relaying of email. SMTP servers will also have their own dedicated address or set of addresses that will be determined by the client using the server.
What is an SMTP relay?
SMTP mail relay is simply a process of transferring/relaying an email from one server to another server for the delivery. Let’s understand this from an example. You are company ‘x’ who wants to send an email to an employee of company ‘Y’. To do this, you will connect to your company x’s SMTP server. Your SMTP server connect and delivers your email to company y’s server. The process of accepting an email from one server to another server is “relaying.”
But please note that if you are sending an email to someone within your company (means same domain) then there is no second server involved in this sending process. This isn’t relaying.
How does SMTP work?
To better understand the SMTP working, we will go through the sending process, the individual rules and commands used in SMTP and also the errors you may get. This is going to be bit technical.
SMTP is based on end-to-end message delivery and the first step is the connection establishment for communication between the mail sender and the mail receiver is required. The SMTP connection built on The Transmission Control Protocol (TCP). When the user hits the ‘send email’, the email client opens an SMTP connection (TCP based connection) to the server and mail sender sends the data in form of command strings over this channel. The SMTP client uses commands to tell the server what to do and the data to be transfer like sender’s email, recipient’s emails, and content.
After that the MTA(Mail transfer agent or Message transfer agent) starts works on the data. MTA first checks the email domain, if domain is same or not. Same domain emails will be sent right away and for different domain server use DNS to identify the recipient’s domain. After that it send email to the right server.
Usually, an SMTP email transaction follows six commands or reply sequences that power the transmission of email messages between servers. Let’s check them out.
It is the command to start the entire email sending process. It begins the communication and tells the email server that the client-server wants to start the mail transaction. The client mentions its domain/IP address after this command.
Example: HELO mailazy.com or EHLO mailazy.com
EHLO is an alternative to
HELO for servers that support the ESMTP or SMTP service extensions.
This command specifies the e-mail address of the sender. It lays down the bounce/return address, defining the return or reverse paths. This tells the SMTP server that a new transaction is about to start and makes the server to reset all its state tables and buffers etc. to accept the email address. Once accepted, it will reply with a 250 OK reply code.
Example: MAIL FROM email@example.com
This command specifies the e-mail address of the recipient. It sends after receiving 250 OK and use to identify the destination mailbox. The sender’s envelope contains the addresses of the recipients and can be repeated multiple times for an email message in order to deliver a single e-mail message to multiple recipients.
Example: RCPT TO firstname.lastname@example.org
This triggers the transfer of data between the client and the server. It shows where the content of the message starts, as opposed to its envelope. An empty line separates the message header and body in the message’s text.
DATA is not just one command but a group of commands in which a server has to reply twice.
- First, the server acknowledges the message and replies with its readiness to take the message. Here server will respond with a 345 reply code.
- Then after completing the end-of-data sequence, it either accepts or rejects the entire message. If accepted and ready for delivery, the server sends another 250 OK code.
The negative responses can further be permanent (5xx codes) or transient (4xx codes).
If a server sends ‘reject,’ then it is a permanent failure, and the client needs to send a bounce message to the respective server.
Example: DATA 354 (server response code) Date: Fri, 13 Jun 2022 00:01:00 From: email@example.com Subject: How SMTP works To: firstname.lastname@example.org body/message
When the email has been sent, the client sends the QUIT command to the server, severing the connection. If it has been successfully closed, the server will reply with a 221 code.
This command is used only to check whether the server can respond.
This command resets the SMTP connection to the initial state. It erases all the buffers and state tables. This command is sent to the server when the mail transaction needs to be aborted. It doesn’t close the connection, but it does reset everything and remove all previous data about the email and the parties involved.
Understanding SMTP error codes
The SMTP server are not always response positive and may return a particular error message.
We can divide SMTP error messages in two groups.
- 4.X.X Persistent Transient Failure: These error codes start with the number “4” followed by two other numbers. They typically mean that there’s a temporary failure with the mail server and your email is not delivered.
- 5.X.X Permanent Error: These error codes begin with the number “5” and are followed by two numbers. They typically signify that the SMTP connection has dropped. If you try to resend the email, it will likely still result in the same error.
We have added a detailed article on SMTP error codes. You can refer to this from here.
Glossary and Terminology related to SMTP
Bounce: An email message that is not delivered is said to have bounced. There are two types of bounce - hard bounce and soft bounce.
Delivered Email: The email is delivered to the recipient’s email address.
Email Address: The combination of a unique user name and a sender domain (email@example.com).
Email Domain: Aka Domain. The right side portion of the email address after ‘@’ sign. For example, In the email address firstname.lastname@example.org. The Domain is mailazy.com
Hard Bounce: A delivery failure for a permanent reason.
IP Address: A unique number assigned to each device connected to the Internet. An IP address can be dynamic or static. Dynamic means it changes each time an email message or campaign goes out (Email sent out from an IP pool), Static means it does not change. Static IP addresses are considered best for sending emails because of a maintained reputation.
IMAP: Internet Message Access Protocol, a standard protocol for accessing email from a server.
POP (Post Office Protocol): Protocol to send or receive messages from an email server.
Queue: For email, a queue is where email messages wait to be processed by the recipient’s mail server.
Server: A program, software, or computer system that distributes email from one mailbox to another, or relays email from one server to another in a network.
SMTP: Simple Mail Transfer Protocol, the most common protocol for sending email messages between email servers.
Soft Bounce: Email sent to an active email address but is not delivered. Often, the problem is temporary.
Spam: Refers to unsolicited email also known as "junk".
Transactional Email: An email sent to an individual recipient for a specific action performed by that person.