What is a protocol?
A protocol consists of a set of rules and procedures which govern the exchange of data between two or more devices. Protocols define how the transmission of data will precisely take place between electronic devices such as computers. They set the standard procedures for communication and exchange of information.
The International Organization for Standardization established the Open Systems Interconnection (OSI). It is one such widely used Internet protocol that lays down the standard for communication over different networks. The model divides the process of data transmission in a series of seven layers.
Other important internet protocols are TCP/IP, HTTPS, SMTP, and DNS.
What is SMTP?
The Simple Mail Transfer Protocol is a communication protocol that allows the users on the same or different computers to send mails over the internet. It involves a particular set of guidelines according to which the communication via mail takes place.
SMTP acts as a push protocol by transmitting the mail on and across the networks. It comes under the application layer of TCP/IP protocol, where it works in a 'store and forward manner.'
SMTP facilitates the mail exchange over networks. After recognizing the respective mail address, it sends the message to one or more recipients. The user can send the mail in various forms, such as text, video, or graphics.
Components of SMTP
There are two primary components of the SMTP client and the SMTP server. The first is User-Agent, and the second is a Mail Transfer Agent.
The User-Agent (UA) is responsible for preparing, creating, and putting the message in the form of an envelope for transmission. The Mail Transfer Agent (MTA) then transfers this message across the internet to the particular recipient.
The SMTP supports a more complex system by adding a relaying system in the process. Under this, more MTAs can be placed at either sending or receiving sides.
If needed, then this relay system can use mail gateways and work without TCP/IP protocols.
Types of SMTP
In the SMTP model, the client-SMTP starts the communication session, whereas the SMTP at the receiver's side responds to the client's request.
The end-to-end SMTP protocol helps to send email to servers at various other organizations. This model acts as a medium of communication between different organizations.
The store-and-forward SMTP model is different from the end-to-end SMTP model. The store-and-forward type is used within an organization only, unlike the end-to-end SMTP.
After contacting the destination's host directly, the SMTP server keeps the mail to itself until the receiver's SMTP successfully receives a copy of the email.
How does SMTP work?
The Transmission Control Protocol (TCP) is the primary connection for communication between the mail sender and the mail receiver. In SMTP, the mail sender sends the data in the form of command strings over this reliable ordered data stream channel.
The SMTP client consisting of the initiating agent, sender, or transmitter initiates the communication session. It issues the command strings and opens the session for corresponding responses from the SMTP server, which involves the listening agent, or receiver. Zero or more SMTP transactions may be there in a course.
Usually, an SMTP transaction follows four command or reply sequences:
- HELO/EHLO command - It tells the email server that the client wants to start the mail transaction. The client mentions its domain name after this command. For example, "HELO e-mail.myhost.com."
- MAIL command - It lays down the bounce address/return address, thereby defining the return-path or reverse-path.
- RCPT command - It specifies the recipient of the message. The sender's envelope contains the addresses of the recipients, to which the RCPT command can be issued multiple times for each recipient.
- DATA- 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 text of the message. However, 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. Then after completing the end-of-data sequence, it either accepts or rejects the entire message.
Apart from the reply of the DATA command, the server can reply in a positive way (2xx reply codes) or a negative way. The negative responses can further be of two types; 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. On the other side, a 'drop' is a positive reply, in which the message is discarded instead of delivery.
In 1982, one of the first MTAs to implement the Simple Mail Transfer Protocol, 'Sendmail' with 4.1cBSD, was released. With time, it became a commonly used mail transfer agent.
Some other SMTP server programs that have become popular include Postfix, qmail, Novell GroupWise, Exim, Novell NetMail, Microsoft Exchange Server, and Oracle Communications Messaging Server.
In 1998 and 1999, new trends in the delivery of emails set in along with the introduction of the Message submission (RFC 2476) and SMTP-AUTH (RFC 2554), respectively.
How are emails sent using SMTP?
The Simple Mail Transfer Protocol is a delivery or 'push' protocol that pushes the mail to the destination server as it arrives.
The process of sending emails via SMTP consists of the following sequential steps:
With the help of an MUA, Mail Transfer Agent program, the user sends an email. The content of the electronic mail consists of two parts, header and body. The former header is the subject of the message, while the body is the main content of the message. The sender and recipient address also comes under the header part. The header acts like an envelope holding the letter (message) in it.
The mail client (mail user agent, MUA) submits the email to a mail server (known as a mail submission agent, MSA) using SMTP on TCP port 587 or the traditional port 25. The MSA further delivers the mail to its mail transfer agent, MTA.
3. Mail Delivery
The two parts of an email address are the username of the recipient and domain name. Let's take, for example, firstname.lastname@example.org, in which "mayank" is the username, and "gmail.com" is the domain.
In case the domain name of the recipient's email address does not match with the sender's domain name, then the mail submission agent (MSA) will send the mail to the (MTA).
Then, the MTA will search for the particular domain to relay the mail. To obtain the target domain, it checks the MX record from the Domain Name System. The MX record contains the information regarding the domain name and IP address of the recipient. Once it locates, MTA establishes the connection with the exchange server and relays the message.
4. Receipt and Processing
After receiving the incoming message, the exchange server delivers it to the Mail Delivery Agent. It stores the email and waits for the retrieval by the user.
5. Access and Retrieval
The user can access the MUA with the login and password. The MUA helps in retrieving the stored email from the MDA.