SMTP (Simple Mail Transfer Protocol) protocol is the standard mechanism for “sending and receiving the electronic mails via the internet”. SMTP is a set of guidelines that enables users to exchange information.
The actual mail transfer is carried out through the message transfer agent i.e. a system should have the client MTA(Mail Transfer Agent) to send mail and it should have a server MTA to receive the mail.
Thus, the SMTP protocol is the protocol that defines the MTA client and MTA server on the internet. Most email clients, such as Apple Mail, Gmail, Outlook, etc rely on SMTP to send or receive messages or emails from a sender to a recipient.
What is Simple Mail Transfer Protocol (SMTP)?
SMTP, which stands for, Simple Mail Transfer Protocol, is an email protocol that is used to send and receive emails over the internet. It is a set of guidelines that are followed to transmit electronic mail over the Internet. The main purpose of the SMTP is to set up communication guidelines between the servers.
Basically, in SMTP the actual transfer of the mail is done through the message transfer agent (MTA). Hence, to send the mail, the system must have the client MTA and similarly, to receive the mail, the system must have the server MTA.
Using the SMTP protocol, a TCP connection to the SMTP server is opened and then the client sends the email across the TCP connection. As soon as the server listens for the TCP connection from any client the connection is established on port 25 and the connection becomes successful hence the clients can send or receive the email immediately.
Consider the below image to understand how the SMTP works.
::
Note :
A brilliant mnemonic to remember what SMTP does is Sending Mail To People.
Let’s take an example to simplify the working of the SMTP protocol and understand it in a better way.
Consider two persons, Alex and Clark. Here, Alex has an account on yahoo with the username, alex@yahoo(dot)com. Whereas, Clark has an account on google with the username, clark@google(dot)com.
Now, Alex wants to send an email to the Clark to share some professional data. Below are the steps that are done to send an email these explain the process of email delivery from the sender to the receiver, here, Alex and Clark respectively.
- Alex writes an email on his machine.
- Alex, then writes the email address of Clark i.e. clark@google(dot)com, and clicks on the button Send.
- Alex’s email client connects to his domain’s SMTP server that pushes the mail. Here, Alex’s server plays the role of an SMTP client.
- Now, Alex’s mail server communicates with Google’s mail server to deliver the message to Clark (clark@google(dot)com).
- After the SMTP handshake between the servers, the SMTP client sends Alex’s mail to Clark’s mail server. Here, Clark’s mail server will play the role of an SMTP server.
- Now, Clark’s SMTP server scans the whole message and recognizes the user name and the domain name.
- At last, Clark’s mail server receives the email, which is also stored in one of the mail clients. And this mail can be fetched and read later through an email client or an application such as Gmail, Outlook, etc.
Components of SMTP
There are four components in the SMTP:
- Mail User Agent (MUA)
- Mail Submission Agent (MSA)
- Mail Transfer Agent (MTA)
- Mail Delivery Agent (MDA)
Working of Simple Mail Transfer Protocol (SMTP)
Let’s see how SMTP works and the best way to understand this is to go over the process of sending emails over the internet which is also discussed in the example above.
Here, let’s see how the working of SMTP takes place behind the process of sending and receiving mail.
- As shown in the image above, a sender drafts the mail and hits the send button. Once an SMTP server is established, email clients can connect and communicate with the server. As the sender has pressed the send button, this triggers the email client to open an SMTP connection to the server to make a connection so that it can send the emails.
- Now, the SMTP client uses various commands available in the SMTP to communicate with the server and to transfer the data like the mail address of the sender.
- Then the Mail Transfer Agent(MTA) ensures that both the mail addresses are from the same email domain. If they are the same, it sends the email. But if not, the server uses the DNS(Domain Name System) to identify the recipient’s domain, and then it’ll send it to the right server.
Model of SMTP System
In the SMTP, the user deals with the User Agent(UA). And, to exchange the mail using the TCP, MTA i.e. mail transfer agent is used.
The MTA is responsible for maintaining the small queue of emails so that it can schedule the delivery of mail when the receiver is not available. Then, the MTA delivers the mail to the mailbox of the recipient.
SMTP-client and SMTP-server
Let’s take a closer look at the communication that happened in the above example between Alex and Clark i.e. Alex’s mail server and Clark’s mail server. Do you remember that Alex’s mail server had to start a link or a channel with Clark’s mail server to communicate or send messages from the sender to the receiver?
Also, the main protocol to handle all the above-mentioned processes was the SMTP. Now, as shown in the example above, Alex is sending the mail i.e. SMTP client (Alex’s mail server) sends the SMTP commands whereas the SMTP server (Clark’s mail server) responds to the commands. Commands like, HELO, MAIL, RCPT, etc. are the commands which are discussed in the next section, are used in the SMTP protocol and the SMTP server responds to these commands.
So, the SMTP client sends the commands to the SMTP server and the server responds with some kind of numerical codes and at last, after the termination of the SMTP session, the receiver receives the message in the email client like Outlook, Gmail, etc.
SMTP Commands
Let’s look at a few commands of SMTP:
Command | Description |
---|---|
HELO | This command is used for beginning the email-sending process and is used to identify the user and full domain name. It is the beginning of the conversation in which the server sends a HELO command back with its domain name. |
This command is used to initiate the message transfer and identifies the originator of the mail. From this command, the server resets everything and is ready to accept the email address and after accepting, it’ll reply with the 250 OK code. | |
RCPT | This command identifies the recipient of the mail and again the SMTP server responds with the same code. |
DATA | This command triggers the transfer of data between the client and the server. |
QUIT | After the email has been sent, the client sends this command to quit the server and if it is closed successfully, the server will reply with a 221 code. |
RSET | To abort or cancel the mail transaction, this command is used. This doesn’t close the connection but it does reset everything and removes all the previous data about the mail and the email addresses. |
Conclusion
- SMTP (Simple Mail Transfer Protocol) protocol is the standard mechanism for electronic mail on the Internet.
- In SMTP the actual transfer of the mail is done through the message transfer agent (MTA).
- There are majorly four components in the SMTP namely, Mail User Agent (MUA), Mail Submission Agent (MSA), Mail Transfer Agent (MTA), Mail Delivery Agent (MDA).
- Bulk emailing is possible only because of the SMTP servers and it is a cost-effective way to send mail in bulk.
- There are various commands in the SMTP and some of them are, HELO, MAIL, RCPT, DATA, QUIT, RSET.