Before learning about SMTP, let’s talk about email first.
- An email, short for electronic mail, is a method of exchanging digital messages, designed to be sent and received electronically over the Internet or other computer networks.
- An email message consists of a text message and may also include attachments such as images, videos, and documents.
- Simple Mail Transfer Protocol (SMTP) is a core component of this email system, enabling the transfer of emails between servers.
In this article, we will discuss SMTP, its features & components, How SMTP works, SMTP commands and response codes in detail, and also discuss MIME Extention.
Table of Contents
Simple Mail Transfer Protocol (SMTP)
- SMTP stands for Simple Mail Transfer Protocol, is a widely-used communication protocol designed to transfer email messages between servers using some commands.
- It is a set of commands, used to only send emails over the internet. So whenever you want to send an email you will be using simple mail transfer protocol (SMTP) commands.
- SMTP is used by the clients for sending emails to the server.
- It is a set of network communication guidelines that are used to set up communication rules between servers.
While sending the mail, SMTP is used two times-
- Between the sender and the sender’s mail server
- Between the sender’s mail server and the receiver’s mail server
You can be memorizing it by just remembering-
- S- Send
- M- Mail
- T- To
- P- People
It’s not his full form, it’s for memorizing, full form of SMTP- Simple Mail Transfer Protocol.
How SMTP Works: A Step-by-Step Guide
The Simple Mail Transfer Protocol (SMTP) is responsible for transmitting email messages between servers. Here is a step-by-step guide to how SMTP works:
- The sender composes an email message and enters the recipient’s email address.
- The sender’s email client sends the message to the sender’s mail server.
- The sender’s mail server uses SMTP to format the message according to the rules of the protocol. This includes adding headers, such as the sender’s and recipient’s email addresses, to the message.
- The sender’s mail server establishes a connection with the recipient’s mail server using port 25.
- The sender’s mail server transmits the message to the recipient’s mail server using SMTP commands.
- The recipient’s mail server acknowledges receipt of the message using SMTP responses.
- The recipient’s mail server stores the message in the recipient’s mailbox.
- The recipient retrieves the message using another protocol, such as IMAP (Internet Message Access Protocol) or POP (Post Office Protocol).
SMTP is a store-and-forward system, which means that the message is temporarily stored on the sender’s and recipient’s mail servers until it can be transmitted. This allows for the message to be delivered even if the recipient’s email server is not available at the time the message is sent.
Overall, SMTP is a reliable and efficient protocol that plays a critical role in the transmission of email messages.
Features of SMTP
- Only for Sending Mail: SMTP is always used only for sending the email, not used for receiving emails. For receiving the email, IMAP or POP3 protocols are used.
- Store-and-Forward: With SMTP, the email message is stored on a server, and then forwarded to the recipient’s email server once it becomes accessible. This ensures that the email is delivered even if there are temporary connectivity issues.
- Application Layer Protocol: SMTP is an application layer protocol because it is used by the client on an application to send emails to the server.
- Works on TCP protocol: It works on TCP protocol at the transport layer because TCP protocol gives guaranteed delivery of data. Actually, there are two protocols on the transport layer, TCP and UDP.
- UDP is a connectionless protocol, where no acknowledgment of sending data.
- TCP is a connection-oriented protocol, which created a connection between the sender and receiver and ensures the delivery of data by using acknowledgment. So SMTP is a connection-oriented protocol because it works with TCP
- Use TCP port 25: It uses TCP port 25, which is a default non-encrypted port. It also uses TCP port 465, which is an encrypted port, used to send message security.
- SMTP is a Push protocol: Actually, There are two protocols: Push and Pull protocol.
- SMTP is a push protocol because it is used only to push mail.
- IMAP and POP3 are the pull protocol because they are used to receiving mail.
- Use 7-bit ASCII format: SMTP uses 7-bit ASCII format for sending each message.
- Authentication: SMTP supports authentication mechanisms, such as username and password, to ensure that only authorized users can send email messages.
- Encryption: SMTP can be used with encryption protocols, such as SSL (Secure Sockets Layer) or TLS (Transport Layer Security), to secure the transmission of email messages and protect against unauthorized access.
Components of Simple Mail Transfer Protocol
The Simple Mail Transfer Protocol (SMTP) is comprised of several components that work together to transmit email messages between servers. These components include:
- Sender’s Mail Server: The sender’s mail server is responsible for sending the email message to the recipient’s mail server. It uses SMTP to format and transmit the message.
- Recipient’s Mail Server: The recipient’s mail server is responsible for receiving the email message from the sender’s mail server. It uses SMTP to communicate with the sender’s mail server and to receive the message.
- Message: The message is the content of the email, including the subject line, body text, and any attachments. The message must be formatted according to the rules of SMTP in order to be transmitted.
- Message Headers: The headers are a set of metadata that accompany the email message. They include information such as the sender’s email address, the recipient’s email address, the subject line, and the date and time the message was sent.
- SMTP Commands: SMTP uses a set of commands to communicate between servers. These commands are used to initiate a connection, transmit the message, and confirm that the message has been delivered.
- SMTP Responses: SMTP uses a set of responses to indicate the status of the transmission. For example, a positive response code indicates that the message was transmitted successfully, while a negative response code indicates that there was an error during the transmission.
- Mail Transport Agent (MTA): The Mail Transport Agent (MTA) is the software that implements the SMTP protocol. It is responsible for formatting and transmitting email messages and for communicating with other MTAs.
By working together, these components ensure that email messages are transmitted reliably and efficiently between servers.
MIME is an extension that extends the limited capability of email.
Actually, SMTP is a pure text-based protocol means it can only handle 7-bit ASCII text. It does not have any capability to transfer other types of data like images, videos, audio, etc. It cannot transfer executable files and binary objects and also cannot transfer the text data of other languages like- French, Japanese, and Chinese, etc.
So to solve these problems Multipurpose Internet Mail Extensions (MIME) were introduced, which were specially designed for SMTP. MIME extension extends the capability of SMTP, which enables users to transfer images, video files, audio files, executable files, etc. It also enables to transfer of messages into other languages like- French, Japanese, etc.
The MIME encoding system uses base64 encoding that converts binary data into text data, which can then be transmitted as part of an email message. The recipient’s email client can then decode the MIME-encoded data and display it in the appropriate format.
SMTP Commands and Response Codes
SMTP is a program, which works as a protocol for sending mail. For sending the mail, the sender’s mail server and the receiver’s mail server communicate with each other using SMTP protocol.
SMTP (Simple Mail Transfer Protocol) uses a set of commands and response codes to transmit email messages between servers.
For communication, Sender’s mail server always sends commands for sending the mail and the receiver’s mail server accepts those commands and always reacts with the response code instead.
Some SMTP commands
- HELO/EHLO: It is the first SMTP command and the conversation starts with this command, use to identify the domain like- gmail.com
- MAIL FROM: It indicates the sender’s email address.
- RCPT TO: It indicates the recipient’s email address. If there are multiple recipients, this command can be repeated multiple times.
- SIZE: Tell the estimated size (in terms of bytes) of the attached email.
- DATA: This command tells the SMTP receiver, next the stream of data will follow.
- VRFY: This is a verify command, used to verify the email address.
- QUIT: This command is used to terminate the connection.
Some SMTP response codes:
- 101: Server connection error (wrong server name or connection port).
- 211: System status (response to HELP command).
- 214: Help message (response to HELP command).
- 220: The server is ready (response to the client’s attempt to establish a TCP connection).
- 221: The server closes the transmission channel.
- 235: Authentication successful (response to AUTH command).
- 250: The requested command is completed. As a rule, the code is followed by OK.
- 354: Start sending the message (response to DATA command).
- 451: Temporary error, try again later.
- 500: Syntax error means the server cannot recognize the command.
- 510: Invalid email address.
- 550: The requested action was not taken because the recipient’s mailbox was unavailable.
- 553: The requested action was not taken because the recipient’s mailbox was not found.
Simple Mail Transfer Protocol Workflow
SMTP (Simple Mail Transfer Protocol) uses a series of commands and response codes to transmit email messages between servers. The basic workflow of SMTP can be summarized as follows:
- Establishing a connection: The client establishes a connection with the SMTP server using the TCP/IP protocol on port 25.
- Introduction: The sending server sends the “HELO” command to the receiving server to introduce itself. The receiving server responds with a “220” response code to indicate that it is ready to receive the email message.
- Sender Information: The sending server sends the “MAIL FROM” command, specifying the sender’s email address.
The receiving server responds with a “250” response code to confirm that the “MAIL FROM” command was accepted.
- Recipient Information: The sending server sends the “RCPT TO” command, specifying the recipient’s email address. The receiving server responds with a “250” response code to confirm that the “RCPT TO” command was accepted.
- Message Data: The sending server sends the “DATA” command to indicate that it is ready to transmit the message data. The receiving server responds with a “354” response code to indicate that it is ready to receive the message data.
- Message Transmission: The sending server transmits the message data, which includes the message header and body. The sending server responds with the “.” (dot) character to indicate the end of the message data.
- Message Confirmation: The receiving server responds with a “250” response code to confirm that the message was successfully received and processed.
- Termination: The sending server sends the “QUIT” command to terminate the SMTP session. The receiving server responds with a “221” response code to confirm that the SMTP session has been terminated.
You can also Read: