From the perspective of a user, sending emails could seem ‘easy’ with little to no complexities involved. Actually, there exists a somewhat complex system that drives emails from the sender until it arrives at the destination of the recipient. There are lots of moving parts in the how-do-emails-get-sent universe. Several factors affect your email deliverability.
If you are interested in how emails get sent and understanding the intricacies prevalent in communication via emails, or you are just interested in grasping the inner workings of email, then learning all about SMTP servers is essential. In this article, we will look at what an SMTP server is and how it works.
Let’s being with what SMTP Protocol is, and work our way up to SMTP servers and how they function.
What is SMTP Protocol?
SMTP protocol is an email sending protocol. SMTP is an acronym for Simple Mail Transfer Protocol. It is basically a set of commands that authenticates and directs the transfer of email. A less technical definition of SMTP is;
S – Send
SMTP Is part of the application layer of the TCP/IP Protocol. If you’re not familiar with the TCP/IP protocol; it is a connection-oriented protocol that guarantees delivery of emails. When you send an email, a session opens between your SMTP server and the mail target server. The TCP/IP protocol will only ensure the delivery of an email if the destination email address is correct and is still in existence.
Using a process called “store and forward”, SMTP moves your email on and across various networks. It works closely with something called Mail/Message Transfer Agent (MTA) to send your email messages to the correct email address. The MTA routes messages between servers, sites, and foreign mail systems.
What is an SMTP Server?
An SMTP server is a computer or an application that is responsible for sending emails. It functions following SMTP protocol. An SMTP server receives emails from the email client. It then passes them on to another SMTP server and relays them to the incoming mail server. Basically, an SMTP server takes the information it has and gives it to other computers, which lets it find the correct inboxes for delivery.
SMTP servers can only deliver outgoing mail. POP3 or IMAP are responsible for receiving incoming emails.
Email servers are categorized into two; (1) outgoing server (2) incoming server.
For the purpose of this article, we will only be dealing with the concept associated with the outgoing mail server, known as SMTP server.
The prime purpose of an SMTP server is for sending, relaying and receiving outgoing mails between email clients and receivers.
Why You Need An SMTP Server?
Without an SMTP server, it is not possible for your email to be sent to its destination. When you hit the “send” button from your email client, your email gets automatically converted into a string of codes and are transferred to your SMTP server. There, the codes are processed accordingly, and the message is relayed to the correct email address.
Along with relaying SMTP email messages, the server also checks whether an active or working email account is sending the outgoing message. In case the email cannot be delivered, it ensures that the email goes back to the sender. This action is to let the sender realize that he has the wrong email address or the receiving server blocks emails from the sender’s ID.
When you compose/type an email using an email client (a program used in composing, sending and receiving emails messages) like Microsoft Outlook and click send, the email travels from your computer to your email server also known as your SMTP server using the SMTP protocol. This server is configured to your email client.
Email clients usually come in two forms, a web-based version like Yahoo mail where users must log in through their browser to access their emails or a client-based version such as Outlook where users install software to access emails from their local computer.
Just like POP3 and IMAP, the SMTP server is also configured in your email client such as Mozilla Thunderbird and the likes, or your mobile device.
Is an SMTP server the same as a normal server?
Technically, yes. Like most servers, the SMTP server processes data to send to another server, but it has the very specific purpose of processing data related to the sending, receiving, and relaying of email. An SMTP server is also not necessarily on a machine. It is an application that is constantly running in anticipation of sending new mail.
Sending Operation Using SMTP Servers
When you use a free email provider like Yahoo, Hotmail, etc your email address uses their domain name and in turn, they allow you to use their email servers. If you use your webmail site to read and send emails, they handle the email server settings that direct your incoming and outgoing emails.
However, if you want to use a local email client like MS Outlook, Apple Mail or Mozilla Thunderbird to send an email, you will need to enter your email provider’s incoming and outgoing email server settings when you set up your email client.
Incoming email server setting tells the email client where it can retrieve your email from, while the outgoing email server setting tells the email client where it can send your email to.
The outgoing server setting is also known as the SMTP server setting.
Let’s quickly examine the key terms involved in the process of sending an email through the SMTP server:
1- Jane’s Email client/ Mail User Agent (MUA)
Meet Jane. Though Jane loves using Yahoo as her service provider, she prefers to use the email client Microsoft Outlook for composing, sending and reading her emails.
Jane uses her email client/MUA application on her laptop to compose, reply to, and read her emails.
2- Jane’s Mail Server
Jane has an email account on Yahoo. The remote machine under the yahoo.com domain manages all the email messages Jane receives. This machine is tasked with the responsibility of sending email messages from Jane to other users on other mail servers.
3- John’s email client/MUA
Meet John. Similar to Jane’s email client, this is the application running on John’s laptop. This application allows him to fetch emails from his mail server. It also allows him to compose messages on his laptop and send them to other people’s mail server. Let’s assume John has a MAC and he uses Apple Mail app as his email client.
4- John’s Mail Server
Similar to Jane’s mail server, John is using Gmail, so his mail server is a Gmail machine.
How does SMTP Server work?
The email Journey
Jane wants to send an email to John.
Let us follow the process that is involved and see the role of an SMTP server:
• Jane’s email address is email@example.com.
• To make sure Outlook (Jane’s email client) can communicate with Yahoo mail servers, she entered Yahoo email server settings when she configured Microsoft Outlook.
• Jane composes an email to her colleague, John.
• After she sends the email to his email address firstname.lastname@example.org, MS Outlook sends John’s email address, her email address and the body of the email to Yahoo’s SMTP server. Jane’s mail server sees that there is a message pending delivery to email@example.com. It starts a communication with the Gmail mail server to allow for this message delivery to happen. This is where the SMTP comes into play.
The SMTP protocol governs the communication between these two mail servers. In this scenario, Jane’s mail server will play the role of an SMTP client while John’s mail server will play the role of an SMTP server.
• Yahoo’s SMTP server then breaks the recipient email address into two parts ; (1) the recipient ID “johnfk” or what displays in front of the “@” sign. (2) the domain name “gmail.com” or what is displayed after the “@” sign.
• Yahoo’s SMTP server then goes out to the internet, and through a series of server conversations, locates the SMTP server for the domain name gmail.com.
• The Yahoo’s SMTP server then passes Jane’s email to Gmail’s SMTP server.
• Once Jane’s email arrives at Gmail’s SMTP server, it will remain there until John logs into his Gmail account and retrieves the email.
Stages in SMTP Protocol
Understanding the stages/phases involved in the SMTP protocol will help us better understand how SMTP Servers function.
There are three stages involved in SMTP protocol;
- The Handshaking/Introductory Stage
Jane’s mail server (the SMTP client) establishes a TCP/IP connection with John’s mail server (The SMTP server). The SMTP server responds with code “220”. The handshaking stage kicks into gear after the code “220” is received by the client. Through this Introductory Stage, the client and the server identify themselves and the identities of the sender of the email and the recipient of the email.
Jane’s mail server sends an EHLO command to John’s mail server and identifies its domain. For example, Jane’s mail server would send “EHLO ”. This command is more or less a “hello message” from the SMTP client to the SMTP server.
Other examples of commands used in the SMTP protocol are DATA, RCPT TO, MAIL FROM, and QUIT.
The SMTP server at Gmail then acknowledges the EHLO message by responding with code “250” along with the services that the SMTP server can support.
A “MAIL FROM” command along with the sender’s information is then sent by the SMTP client. For example, “MAIL FROM firstname.lastname@example.org”.
Upon receipt of this command, the SMTP server responds again with the same code 250 to indicate that it has no problem accepting messages from the user, Jane.
The SMTP client then sends an “RCPT TO” command along with the email address of the recipient. It would look like this; “RCPT TO email@example.com”.
The SMTP server ensures that the user “Jane” exists. When it authenticates the existence of the user, Jane, the SMTP server sends back a 250 acknowledgement which indicates it’s acceptance of the message from Jane to be delivered to John.
- Email Message Transfer Stage
The SMTP client sends the command “DATA” to the server just to make sure the server-side is ready for the content (body of the email).
John’s mail server in response, replies with the code “354”. This shows the readiness to receive the message.
Upon receipt of this code, the client is now ready to send the email message from Jane to John’s mail server.
The email message is sent out line by line and is only acknowledged after the “End of Mail” special line is sent to the mail server. The “End of Mail” special line is a line that only has a “.” by itself.
The “.” sent by the client to the server indicates the end of the message. This also serves as a signal to the server that it can start processing the email message.
Once John’s mail server receives the “.”, it then acknowledges receiving the whole message by sending a 250 code back to the client.
Now the email is stored on the Gmail server and is retrieved when John logs into his Gmail account.
- Ending Connection Stage
Jane’s mail server sends a final command to John’s mail server. The “QUIT” command is sent by the client to the mail server. This is to indicate the intention of the client to close the connection it has with John’s mail server. John’s mail server accepts this request by replying with the “221” code.
And there you have it!
In conclusion, an SMTP server is like a mailman. The mailman (SMTP server) picks up the mail from your home, then takes your mail, finds the correct route, and delivers your mail to the destination mailbox.