Videos
Check out our tutorial video series.
Inspecting the operation and significance of SMTP protocol. Delve into the components, security protocols, and network function. Learn more here.
Every day, we send and receive emails that involve a complex system despite the simplicity of the protocol. In this article, we will delve into the fundamental characteristics and operations of SMTP.
SMTP, or Simple Mail Transfer Protocol, is an application layer protocol responsible for transferring emails between servers and computer networks. The original model was introduced in 1982, and the SMTP client and SMTP server communicate using commands and responses. SMTP can only send simple messages, so the Multipurpose Internet Mail Extensions (MIME) protocol is used for attachments, non-English messages, and HTML/CSS formats.
ESMTP, or Extended Simple Mail Transfer Protocol, was introduced in 1995 to create a unified structure for future extensions. It uses a new EHLO command and allows additional parameters in SMTP's MAIL FROM and RCPT TO commands. ESMTP and SMTP are both widely used today.
SMTPS, or Simple Mail Transfer Protocol Secure, secures SMTP with 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.
There are four main types of SMTP systems: Originating SMTP, Delivery SMTP, Relay SMTP, and Gateway SMTP. The main components of the SMTP model are User, Sender-SMTP (SMTP client), and Receiver-SMTP (SMTP server). Mail agents, such as MUA (Mail User Agent), MSA (Mail Submission Agent), MTA (Mail Transfer Agent), and MDA (Mail Delivery Agent) also participate in the process of sending and receiving emails.
SMTP relay is the process of transmitting emails between SMTP servers hosted on different domains. An SMTP session begins when the client opens a Transmission Control Protocol (TCP) connection to the SMTP server. The server responds with an opening message, and the client then sends a HELO command (EHLO for ESMTP) and identifies itself. The email transfer stage will then begin.
SMTP queue is a set of emails that are waiting to be delivered. Emails are usually put in the queue when the receiving SMTP server isn't ready to accept emails, or you're sending large volumes at once. SMTP commands and responses are used in the process of sending and receiving emails.
SMTP (Simple Mail Transfer Protocol) is a communication protocol used for sending and receiving email messages over the internet. SMTP infrastructure includes SMTP servers, mail agents, and SMTP relay.
Overall, SMTP infrastructure works by using SMTP servers to send and receive email messages, mail agents to manage the messages, and SMTP relay to transfer the messages between different SMTP servers. Together, these components allow email messages to be sent and received across the internet in a reliable and efficient manner.
SMTP servers are computers that are responsible for sending and receiving email messages. When an email message is sent, it is sent to an SMTP server that is responsible for delivering it to the recipient's mailbox. When an email message is received, it is received by an SMTP server and stored in the recipient's mailbox.
Mail agents are software programs that run on SMTP servers and are responsible for managing email messages. When an email message is received by an SMTP server, it is passed to a mail agent that is responsible for processing it. The mail agent checks the recipient's mailbox and delivers the message to the appropriate mailbox. Similarly, when an email message is sent, the mail agent is responsible for sending it to the SMTP server.
Mail Agent | Description |
---|---|
MUA (Mail User Agent) | A software application used by end-users to manage their email messages. Also known as an email client, examples include Microsoft Outlook, Apple Mail, and Mozilla Thunderbird. |
MSA (Mail Submission Agent) | A software program responsible for accepting email messages from MUAs and submitting them to the MTA for delivery. MSAs typically listen on port 587 and use the SMTP protocol with STARTTLS encryption. Examples include OpenSMTPD and Postfix. |
MTA (Mail Transfer Agent) | A software program responsible for routing and delivering email messages between SMTP servers. MTAs use the SMTP protocol to transfer email messages and are typically configured as either inbound or outbound servers. Examples include Sendmail, Exim, and Qmail. |
MDA (Mail Delivery Agent) | A software program responsible for delivering email messages to the recipient's mailbox. MDAs typically store email messages in a mailbox format, such as mbox or Maildir. Examples include Procmail and Dovecot. |
SMTP relay is the process of transferring email messages from one SMTP server to another. When an email message is sent, it is sent to the SMTP server of the sender's email provider. The SMTP server then sends the message to the SMTP server of the recipient's email provider. This process may involve one or more intermediate SMTP servers, which are responsible for relaying the message to the next SMTP server in the chain. SMTP relay is necessary to ensure that email messages can be sent and received across different email providers and networks.
SMTP is a protocol based on commands and responses. The SMTP client sends commands to the SMTP server, and the server responds with a status code and message. Here are some of the most common SMTP commands and responses.
Command | Description |
---|---|
HELO <domain> | Identifies the sender's domain to the SMTP server. |
EHLO <domain> | Identifies the sender's domain to the SMTP server and requests extended features. |
MAIL FROM: <address> | Specifies the sender's email address. |
RCPT TO: <address> | Specifies the recipient's email address. |
DATA | Indicates the start of the email data. |
QUIT | Terminates the SMTP session. |
AUTH | Initiates an authentication process with the SMTP server. |
NOOP | Does nothing, but can be used as a keep-alive message. |
RSET | Resets the current mail transaction. |
HELP | Requests help information from the SMTP server. |
VRFY | Verifies the existence of an email address. |
EXPN | Expands a mailing list. |
TURN | Switches the SMTP session to reverse mode. |
Open the command prompt (Windows) or terminal (Mac/Linux) and type the following command to connect to the SMTP server:
Replace smtp.server.com with the actual SMTP server address.
After establishing the connection, type the following commands to start the email transaction and identify yourself as the sender:
Replace yourdomain.com with your actual domain name and sender@example.com with the email address of the sender.
Type the following command to specify the recipient's email address:
Replace recipient@example.com with the email address of the recipient.
Type the following command to start the data transaction:
Type the following commands to specify the email subject and body:
Note that there should be a blank line after the To: field.
Type a period . on a new line to indicate the end of the email data:
Type the following command to close the connection and send the email:
If everything is successful, the email should be sent and delivered to the recipient's inbox.
When you issue an SMTP command the server replies with a response status code. Here are some common codes and what they mean.
Code | Response Message | Description |
---|---|---|
220 | Service ready | This response indicates that the SMTP server is ready to receive commands. |
250 | Requested mail action okay, completed | This response indicates that the requested action was successful. |
251 | User not local; will forward to <forward-path> | This response indicates that the recipient's mailbox is not hosted on the current server and will be forwarded to another server. |
354 | Start mail input; end with <CRLF>.<CRLF> | This response indicates that the server is ready to receive the email data. |
421 | Service not available, closing transmission channel | This response indicates that the SMTP server is not available or is unable to process the request at the moment. |
450 | Requested mail action not taken: mailbox unavailable | This response indicates that the recipient's mailbox is unavailable. |
451 | Requested action aborted: local error in processing | This response indicates that the server encountered an error while processing the request. |
452 | Requested action not taken: insufficient system storage | This response indicates that the server is running low on storage space and cannot process the request. |
500 | Syntax error, command unrecognized | This response indicates that the SMTP command is not recognized by the server. |
501 | Syntax error in parameters or arguments | This response indicates that there is a syntax error in the parameters or arguments of the SMTP command. |
502 | Command not implemented | This response indicates that the SMTP command is not implemented by the server. |
503 | Bad sequence of commands | This response indicates that the SMTP command was issued in the wrong order or context. |
504 | Command parameter not implemented | This response indicates that the specified command parameter is not implemented by the server. |
550 | Requested action not taken: mailbox unavailable or not local | This response indicates that the recipient's mailbox is unavailable or does not exist. |
551 | User not local; please try <forward-path> | This response indicates that the recipient's mailbox is not hosted on the current server and should be forwarded to another server. |
552 | Requested mail action aborted: exceeded storage allocation | This response indicates that the server has exceeded its storage allocation and cannot process the request. |
553 | Requested action not taken: mailbox name not allowed | This response indicates that the recipient's mailbox name is not allowed or is invalid. |
554 | Transaction failed | This response indicates that the SMTP transaction failed for some reason, such as an invalid email address or spam detection. |
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.
Port | Description |
---|---|
25 | This is the default SMTP port used for email delivery. It is used for outbound email from a mail client to an SMTP server. |
465 | This is the port used for SMTP over SSL (SMTPS). It is a secure version of SMTP that encrypts the connection between the email client and the server. |
587 | This is the port used for SMTP submission. It is used for inbound email to an SMTP server from a mail client. This port supports the use of STARTTLS encryption. |
2525 | This is an alternate port used for SMTP. It is sometimes used by ISPs and web hosting providers as an alternative to port 25. |
SMTP is an outbound email server used for sending and delivering emails, while IMAP and POP3 are message access protocols used for retrieving incoming messages from the email server. Most programming languages allow users to route outgoing emails through SMTP either natively or with the help of different libraries.
IMAP is often preferred over POP3 because it allows for email messages to be stored on the server, which enables better synchronization between email clients and the server, supports advanced features, and reduces storage requirements on the client device.
Here is an example using telnet:
While POP3 is a simpler protocol than IMAP, it has some advantages in certain situations. For example, POP3 allows users to download email messages to a single device and manage them locally, which can be useful for users with limited internet connectivity or storage capacity. Additionally, POP3 can be faster than IMAP for retrieving email messages since it does not require continuous synchronization with the email server. However, overall, IMAP is usually considered to be a more versatile and feature-rich protocol than POP3.
Here is an example of POP3 using telnet:
SMTP trial services offer users the ability to test their SMTP setup before committing to a full-scale implementation. These services typically provide a limited-time trial period during which users can send test emails to ensure that their SMTP configuration is working correctly. SMTP trial services are especially useful for developers and system administrators who need to test their email infrastructure before deploying it in a production environment.
SMTP online services provide users with a convenient way to send and receive emails over the internet. These services are hosted in the cloud and offer features such as email forwarding, spam filtering, and email archiving. SMTP online services are ideal for small businesses and individuals who need a reliable and cost-effective solution for managing their email communication.
Sending email with SMTP can be achieved in many ways as SMTP is simply protocol. That means you can use any programming language or library to send emails with SMTP. For example, you can use the JavaMail API to send emails with SMTP in Java. Or you can use the Nodemailer library to send emails with SMTP in Node.js.
Here is an example using powershell on Windows:
Open the Terminal app on your Mac.
Type the following command to open a text editor and create a new email message:
In the text editor, enter the email message you want to send, including the subject and body of the email.
Save the message and exit the text editor by pressing Ctrl + X, then Y, and finally Enter.
Type the following command to send the email using the sendmail command:
Replace recipient@example.com with the email address of the recipient.
If prompted, enter your email password to authenticate with the SMTP server.
If the email is successfully sent, you should see a message similar to the following:
Here is an example using Python on Linux:
Save the file as then run
in a terminal to send your email.
SMTP as a service is provided for two main purposes: testing and sending. In terms of testing, SMTP service implies a fake SMTP server that captures outgoing mail. When it comes to email sending, SMTP service is synonymous with SMTP relay service.
MailSlurp is an Email Delivery Platform that combines Email Testing and Email Sending. It's a complete email infrastructure that allows users to test SMTP servers, send emails with it, and monitor their performance with actionable analytics.
Check out our tutorial video series.
Email and SMS guides for automation and testing.
View github project code for multiple languages.
Latest posts from the MailSlurp team.
Test, build, and automate messaging with a free MailSlurp account.