Home Computer Networks Simple Mail Transfer Protocol - SMTP

Simple Mail Transfer Protocol – SMTP [Tutorial]

Simple Mail Transfer Protocol (SMTP) is a protocol to send electronic mail from one user to another user in a reliable and efficient manner. Mail servers such as Gmail, Outlook, etc use SMTP for sending an email. SMTP uses Transmission Control Protocol and runs on port number 25. For SMTP to work, both sender and receiver need not be online at the same time.

SMTP Working

An SMTP session is initiated when a client opens a connection to a server by issuing the EHLO command and the server responds with an opening message. The SMTP session consists of commands originated by the SMTP clients and the responses from the SMTP Server.  SMTP sessions are stateful. A session can contain zero or more SMTP transactions. Three important commands in SMTP transaction-

  1. MAIL – The transaction starts with the mail command. It does the sender identification.
  2. RCPT – It gives the receiver information. If RCPT command exists before previous MAIL command the n server throws 503 “Bad Sequence of Commands” response. This command can be issued multiple times.
  3. DATA – This command tells about the beginning of a message. Once accepted the SMTP server immediately replies with 354 responses and when the entire message is received SMTP server again replies with “250 OK”. SMTP indicates the end of the mail data by sending a line containing only a “.” (period or full stop).

The client who wants to send an email, the Mail client(or formally known as mail user agent or SMTP client) opens a full-duplex(two way)  TCP connection with the Mail Server(SMTP Server) which is always in listening mode at the port number (25) and an SMTP session will be created. The Mail client uses TCP because it is a reliable ordered data stream channel for communication, hence the entire message will be delivered to the server without any data loss.

Simple Mail Transfer Protocol - SMTP
Simple Mail Transfer Protocol

SMTP Components

SMTP has 4 key components –

  1. Mail User Agent (MUA) – Mail User Agent or User-Agent is the client application for sending and receiving emails. Ex – Gmail, Microsoft Outlook, etc.
  2. Mail Submission Agent (MSA) – Mail Submission Agent is a server that receives mail from MUA, checks for errors, and in case of no errors pass it to the SMTP server. There exist Mail transfer agents that work as a mail submission agent too.
  3. Mail Transfer Agent (MTA) – Mail Transfer Agent receives the email from MSA or MUA(if MSA is not used) and passes the mail(using Simple Mail Transfer Protocol SMTP) to other MTA. An MTA works in the background, while the user can’t interact directly with a mail transfer agent. It will also find the MX record from the receivers’ DNS zone. Ex – Postfix, SendMail etc.
  4. Mail Delivery Agents (MDA) – Mail Delivery agents are responsible for delivering emails to recipients’ mailboxes.


We have created a system design guide to help ace your next System Design Interview for free. Read here…


Please enter your comment!
Please enter your name here