top of page

Email is emerging as one of the most valuable services on the internet today. Most internet systems use SMTP as a method to transfer mail from one user to another. SMTP is a push protocol and is used to send the mail whereas POP (post office protocol) or IMAP (internet message access protocol) is used to retrieve those emails at the receiver’s side. 

What is Simple Mail Transfer Protocol?

SMTP is an application layer protocol. The client who wants to send the mail opens a TCP connection to the SMTP server and then sends the mail across the connection. The SMTP server is an always-on listening mode. As soon as it listens for a TCP connection from any client, the SMTP process initiates a connection through port 25. After successfully establishing a TCP connection the client process sends the mail instantly. 

SMTP Protocol

The SMTP model is of two types:

  • End-to-End Method

  • Store-and-Forward Method

The end-to-end model is used to communicate between different organizations whereas the store and forward method is used within an organization. An SMTP client who wants to send the mail will contact the destination’s host SMTP directly, to send the mail to the destination. The SMTP server will keep the mail to itself until it is successfully copied to the receiver’s SMTP. 
The client SMTP is the one that initiates the session so let us call it the client-SMTP and the server SMTP is the one that responds to the session request so let us call it receiver-SMTP. The client-SMTP will start the session and the receiver SMTP will respond to the request. 

Model of SMTP System 

In the SMTP model user deals with the user agent (UA), for example, Microsoft Outlook, Netscape, Mozilla, etc. To exchange the mail using TCP, MTA is used. The user sending the mail doesn’t have to deal with MTA as it is the responsibility of the system admin to set up a local MTA. The MTA maintains a small queue of mail so that it can schedule repeat delivery of mail in case the receiver is not available. The MTA delivers the mail to the mailboxes and the information can later be downloaded by the user agents.

Components of SMTP

  • Mail User Agent (MUA): It is a computer application that helps you in sending and retrieving mail. It is responsible for creating email messages for transfer to the mail transfer agent(MTA).

  • Mail Submission Agent (MSA): It is a computer program that receives mail from a Mail User Agent(MUA) and interacts with the Mail Transfer Agent(MTA) for the transfer of the mail.

  • Mail Transfer Agent (MTA): It is software that has the work to transfer mail from one system to another with the help of SMTP.

  • Mail Delivery Agent (MDA): A mail Delivery agent or Local Delivery Agent is basically a system that helps in the delivery of mail to the local system. 

Working of SMTP
Below mentioned are the steps of the working of SMTP [Simple Mail Transfer Protocol].

  • Communication between the sender and the receiver: The sender’s user agent prepares the message and sends it to the MTA. The MTA’s responsibility is to transfer the mail across the network to the receiver’s MTA. To send mail, a system must have a client MTA, and to receive mail, a system must have a server MTA. 

  • Sending Emails: Mail is sent by a series of request and response messages between the client and the server. The message which is sent across consists of a header and a body. A null line is used to terminate the mail header and everything after the null line is considered the body of the message, which is a sequence of ASCII characters. The message body contains the actual information read by the receipt. 

  • Receiving Emails: The user agent on the server-side checks the mailboxes at a particular time of intervals. If any information is received, it informs the user about the mail. When the user tries to read the mail it displays a list of emails with a short description of each mail in the mailbox. By selecting any of the mail users can view its contents on the terminal.

Advantages of SMTP

  • If necessary, the users can have a dedicated server.

  • It allows for bulk mailing.

  • Low cost and wide coverage area.

  • Offer choices for email tracking.

  • Reliable and prompt email delivery.

Disadvantages of SMTP

  • SMTP’s common port can be blocked by several firewalls.

  • SMTP security is a bigger problem.

  • Its simplicity restricts how useful it can be.

  • Just 7-bit ASCII characters can be used.

  • If a message is longer than a certain length, SMTP servers may reject the entire message.

  • Delivering your message will typically involve additional back-and-forth processing between servers, which will delay sending and raise the likelihood that it won’t be sent.

SMTP

  • SMTP stands for Simple Mail Transfer Protocol.

  • SMTP is a set of communication guidelines that allow software to transmit an electronic mail over the internet is called Simple Mail Transfer Protocol.

  • It is a program used for sending messages to other computer users based on e-mail addresses.

  • It provides a mail exchange between users on the same or different computers, and it also supports:

    • It can send a single message to one or more recipients.

    • Sending message can include text, voice, video or graphics.

    • It can also send the messages on networks outside the internet.

  • The main purpose of SMTP is used to set up communication rules between servers. The servers have a way of identifying themselves and announcing what kind of communication they are trying to perform. They also have a way of handling the errors such as incorrect email address. For example, if the recipient address is wrong, then receiving server reply with an error message of some kind.


     Components of SMTP

  • First, we will break the SMTP client and SMTP server into two components such as user agent (UA) and mail transfer agent (MTA). The user agent (UA) prepares the message, creates the envelope and then puts the message in the envelope. The mail transfer agent (MTA) transfers this mail across the internet.

  • SMTP allows a more complex system by adding a relaying system. Instead of just having one MTA at sending side and one at receiving side, more MTAs can be added, acting either as a client or server to relay the email.

  • The relaying system without TCP/IP protocol can also be used to send the emails to users, and this is achieved by the use of the mail gateway. The mail gateway is a relay MTA that can be used to receive an email.

Working of SMTP

  1. Composition of Mail: A user sends an e-mail by composing an electronic mail message using a Mail User Agent (MUA). Mail User Agent is a program which is used to send and receive mail. The message contains two parts: body and header. The body is the main part of the message while the header includes information such as the sender and recipient address. The header also includes descriptive information such as the subject of the message. In this case, the message body is like a letter and header is like an envelope that contains the recipient's address.

  2. Submission of Mail: After composing an email, the mail client then submits the completed e-mail to the SMTP server by using SMTP on TCP port 25.

  3. Delivery of Mail: E-mail addresses contain two parts: username of the recipient and domain name. For example, vivek@gmail.com, where "vivek" is the username of the recipient and "gmail.com" is the domain name.
    If the domain name of the recipient's email address is different from the sender's domain name, then MSA will send the mail to the Mail Transfer Agent (MTA). To relay the email, the MTA will find the target domain. It checks the MX record from Domain Name System to obtain the target domain. The MX record contains the domain name and IP address of the recipient's domain. Once the record is located, MTA connects to the exchange server to relay the message.

  4. Receipt and Processing of Mail: Once the incoming message is received, the exchange server delivers it to the incoming server (Mail Delivery Agent) which stores the e-mail where it waits for the user to retrieve it.

  5. Access and Retrieval of Mail: The stored email in MDA can be retrieved by using MUA (Mail User Agent). MUA can be accessed by using login and password.

How to Find My SMTP Server Name on My Computer

If you are attempting to configure or troubleshoot your email program, you might be asked to check your SMTP server settings. Knowing how to find this setting and provide the information can save you a lot of time and a lot of hassle.

Step 1

Open Internet Explorer, and click on "Tools" then "Internet Options." Click on "Programs," and take note of the email program you are using. Check the website of the email manufacturer, i.e. Microsoft.com for Outlook and Outlook Express, for specific instructions on how to find the SMTP server.

Step 2

Find the SMTP server on your own by opening a DOS window. To open the DOS window click on the "Start" button, choose "Run" from the menu, and type "CMD" in the box. Click "OK" to open the DOS window. When the DOS window opens, type either "ping.smtp.mysite.com" or "ping mail.mysite.com." When the server responds to the request, write down the name of the server.

Step 3

Click "Tools," then "Accounts," then "Mail" if you are using the popular Outlook Express program for your email. Select the "Default" account, and choose "Properties" from the menu. Choose the "Server" tab and choose "Outgoing Mail." This is the name of your SMTP server.

What is ESMTP?
ESMTP or Extended Simple Mail Transfer Protocol was first introduced in 1995 in the RFC 1869. The purpose was to create a unified structure for all future extensions. The extensions aim to add functionalities that SMTP lacks by default. RFC 5321 consolidated and obsoleted previous documents. 
ESMTP uses a new EHLO command to initiate the connection. It also allows the use of additional parameters in SMTP’s MAIL FROM and RCPT TO commands. As a result, ESMTP removes the 512-character limit for additional parameters and leaves it only for cases when additional parameters aren’t defined. 
Both ESMTP and SMTP are widely used today. If the EHLO command isn’t supported, the connection should fall back to the SMTP and its HELO command. 
Speaking of extensions, we should also mention the SMTP-AUTH extension, which adds an authentication step to the process. This means that the mail client should log in to the mail server using its username and password. While SMTP authentication can’t protect against spoofing, it is an important security measure. 
What is SMTPS? 
SMTPS or Simple Mail Transfer Protocol Secure is a method that secures SMTP with the help of transport layer security (TLS) or Secure Sockets Layer (SSL) protocols. These security layers encrypt messages to prevent spammers or spoofers from viewing the contents of the emails. 
Though SSL is still widely used, TLS (more precisely, its 1.3 version) is considered to be the safest protocol for email encryption. For more information on SMTP security, read our dedicated blog post. 
Types of SMTP
RFC 5321 differentiates between four types of SMTP systems:

  • Originating SMTP is the first system that interacts with the internet as it introduces mail; 

  • Delivery SMTP is the system that receives emails from the internet and delivers them to the recipients; 

  • Relay SMTP relays emails between SMTP servers or MTAs (more on transfer agent meaning below) without modifying the message in any way; 

  • Gateway SMTP or SMTP gateway also transfers emails between different servers but, unlike SMTP relay, it’s allowed to transform the message if needed. SMTP gateways are usually firewalls that rewrite addresses or intermediary SMTP servers. 

SMTP infrastructure 
As we saw above, the main components of the SMTP model are User, Sender-SMTP (SMTP client), and Receiver-SMTP (SMTP server). However, mail agents also participate in the process of sending and receiving emails. Moreover, the SMTP model includes SMTP relay in specific scenarios. Let’s see what each of them means and what function they have. 
SMTP server 
SMTP server is an application for sending emails. It receives electronic messages from email clients (Gmail, Yahoo! Apple Mail, AOL, etc.) and transfers them to other servers. These can be other SMTP servers or an incoming mail server. 
SMTP email server can be local or cloud-based. A local SMTP server is a good option for those who don’t want to depend on third-party servers. On the other hand, a cloud-hosted SMTP server requires less effort and can be more secure in the majority of cases. 
Mail Agents 
There are four main agents: 

  • MUA (Mail User Agent) is the email client we mentioned above. It’s an application or a website that you use to send and receive email messages.

  • MSA (Mail Submission Agent) receives emails from the email client, checks its headers, and verifies that the addresses are indicated correctly. 

  • MTA (Mail Transfer Agent) is a sendmail program that processes and transfers emails. It receives messages from the MSA. Most modern MTAs take on MSA’s responsibilities. In that case, message transfer won’t include MSAs. The most popular MTAs are Sendmail, Postfix, and Exim.

  • MDA (Mail Delivery Agent) is the final agent before your emails get delivered to the recipient’s SMTP server and then retrieved through inbound email servers (IMAP or POP3). 

Note that the lines between agents’ responsibilities can be blurry at times, yet they are still useful for illustrative purposes. In the real world, MUAs, MTAs, and SMTP servers are the most essential components of email delivery. 
SMTP relay 
SMTP relay is the process of transmitting emails between SMTP servers hosted on different domains (from @gmail.com to @yahoo.com, for example). 
MTAs check if the domain names are the same. If they are, the SMTP relay won’t happen. But if the domains aren’t the same, MTAs will query Domain Name System (DNS) records to find the IP address for the recipient’s domain. Once the IP is located, they will route the message between one or multiple MTAs (SMTP relay) until it’s finally delivered to the recipient’s SMTP server. 
How does SMTP work?
An SMTP session begins when the client opens a Transmission Control Protocol connection (TCP connection, sometimes called TCP/IP) to the SMTP server. The server responds with an opening message, expressed with code 250. This process is often called an SMTP handshake. 
The client then sends a HELO command (EHLO for ESMTP) and identifies itself. It often follows up the command with the domain name or IP address. In non-technical words, the client says, “Hello, my name is John the Client, I’m sending an email from gmail.com, and my IP is 192.0.2.0”. The server will respond with code 250 again. 
After that, the email transfer stage will begin. Email contents will be transferred step-by-step with MAIL FROM (john@gmail.com), RCPT TO (oliver@gmail.com), and DATA (‘Hey, how have you been?’) commands. If the server accepts the transaction, the client will transfer email headers. It’s necessary to use an end-of-line indicator (period ‘.’) once everything has been transmitted. 
The server will respond with code 250 if the transaction is successful. The client will initiate the termination of the SMTP connection with the QUIT command, and the server will close the transmission channel with code 221. 
This is, of course, a simplified example without an SMTP relay, forwarding, gateways, or error codes. For more information on these, please refer to RFC 5321. 
What about the SMTP queue? 
SMTP queue is a set of emails that are waiting to be delivered. Emails are usually put in the queue when receiving SMTP server isn’t ready to accept emails, or you’re sending large volumes at once. When the server responds, the emails will be delivered one by one. SMTP queue is a sort of buffer between you and the receiving server. 
SMTP commands and responses
We mentioned some of the SMTP commands and responses in the example above. But, while sending emails with SMTP, you may encounter other commands and responses. 
In general, commands are alphabetic character strings ending with <CRLF>. If additional parameters follow, the characters will be terminated by <SP>. 
Responses (or replies) are numeric completion codes that can be positive or negative. Typically, they are followed by a text string. 
Commands and responses are composed of an ASCII character set. 
Commands 

  • HELO/EHLO – initiates the start of the SMTP session.

Syntax: "EHLO" SP ( Domain / address-literal ) CRLF or"HELO" SP Domain CRLF

  • MAIL FROM – initiates mail transaction and includes the reverse path and sometimes optional parameters. 

Syntax: MAIL FROM:<reverse-path> [SP <mail-parameters> ] <CRLF>

  • RCPT TO – indicates the recipient(s) and includes their email address (a.k.a. forward-path) as an argument. 

Syntax: RCPT TO:<forward-path> [ SP <rcpt-parameters> ] <CRLF>

  • DATA – asks the server’s permission to transfer data and does so once it receives a positive reply. 

Syntax:  "DATA" CRLF

  • VRFY – asks the server to verify if the mailbox in the argument exists on the local host. 

Syntax: "VRFY" SP String CRLF

  • EXPN – does the same as VRFY but for the mailing list. 

Syntax: "EXPN" SP String CRLF

  • NOOP – checks the ability of the server to respond. 

Syntax: "NOOP" [ SP String ] CRLF

  • QUIT – initiates the termination of the connection 

Syntax: "QUIT" CRLF

  • HELP – asks the server to verify which commands it supports. It may include a specific command as an argument. 

Syntax: "HELP" [ SP String ] CRLF

  • RSET – resets the SMTP connection and erases all the buffers and state tables. The SMTP connection will be reversed to the initial state. 

Syntax: "RSET" CRLF
SMTP protocol may also support some ESMTP commands, such as STARTTLS, AUTH, and others. 
Responses 
Common positive responses 

  • 250 – the requested action is okay or completed 

  • 211 – system status or reply to HELP

  • 220 – <domain> service is ready 

  • 221 – <domain> closing the transmission channel 

  • 354 – start mail input (usually responds to DATA command) 

Negative responses or error codes

  • 500 – syntax error or command couldn’t be recognized 

  • 503 – bad sequence of commands

  • 252 – the server can’t verify the user. It will still accept the message and attempt the delivery (responds to VRFY command)

  • 450 – mailbox unavailable 

  • 510 – invalid email address 

SMTP ports
SMTP ports are communication endpoints that help identify the exact location of internet addresses. The most common ports used with SMTP are 25, 465, 587, and 2525. 

  • 25 is the oldest SMTP port, but using it for email submission is no longer common. As it doesn’t have security mechanisms, spammers abuse it heavily. For that reason, internet service providers (ISPs) usually block port number 25. It’s recommended to use it only as a relay port. 

  • 465 is more secure compared to 25, but it’s not an official SMTP port and is now deprecated. It supports SSL encryption. Still, it’s recommended to avoid using it whenever possible. 

  • 587 is the default SMTP port recommended with STARTTLS. Almost all email service providers support it. 

  • 2525 is an alternative to 587. It can be used when 587 is blocked or unavailable. 2525 has never been recognized as an official SMTP port. Regardless, most ISPs allow transactions through this port. 

Comparing SMTP, IMAP, and POP3
Apart from SMTP, the most common email protocols are IMAP and POP3. SMTP is an outbound email server used for sending and delivering emails. IMAP and POP3 are message access protocols used for retrieving incoming messages from the email server. 
IMAP is an Internet Message Access Protocol that connects to the server and downloads messages on request. The messages won’t be deleted once the connection is terminated. With IMAP, users can access their emails from any computer or device. 
POP3 or Post Office Protocol 3 also connects to the server, but it downloads all the received messages. Once that’s completed, it will delete all the emails from the server. Unlike IMAP, POP3 is device-dependent. 
More information on the differences between these protocols is available here
How to send emails with SMTP 
One of the main benefits of SMTP is that it makes it easy to send emails from different apps or devices. Most programming languages allow users to route outgoing emails through SMTP either natively or with the help of different libraries. Unlike Web API (or Email API), SMTP integration doesn’t require advanced coding skills. 
You’ll need working SMTP credentials (such as host, port, username, password, and encryption) and the relevant programming language to complete that task. You can check out our recent blog post for more details on that. 
SMTP as a service – testing and sending 
SMTP (or, more precisely, SMTP server) is provided to users as a service for two main purposes – testing and sending. 
In terms of testing, SMTP service implies a fake SMTP server that captures outgoing mail. That way, emails don’t reach real inboxes, creating a safe environment for testing. 
When it comes to email sending, SMTP service is synonymous with SMTP relay service. Email providers have their own SMTP servers that enable users to send marketing or transactional emails. 
Ideally, these two SMTP services can be combined into one robust tool such as Mailtrap
Mailtrap is an Email Delivery Platform that combines Email Testing and Email Sending. It’s a complete email infrastructure that allows users to test SMTP server, send emails with it, and monitor their performance with actionable analytics. 
Email Testing is a Sandbox that captures all the SMTP traffic in a virtual inbox and eliminates the chances of spamming users. You can easily inspect and debug your emails in staging with HTML/CSS or spam checks, view tech info, or use manual/automatic forward features. Email Testing provides multiple inboxes for different projects and product stages. 
Email Sending is an infrastructure with high email deliverability rates by design. With its Email API and SMTP service, the integration is smooth and effortless. All you need to do is verify your domain and choose the preferred method of integration. Once that’s done, you can reach recipients’ inboxes in a matter of seconds. 
Email Sending also has actionable in-depth analytics with drill-down reports and helicopter-view dashboards that keep you on top of your deliverability metrics. 

bottom of page