You've got mail. But how did it get here? A comic about an email's incredible journey through the Wild West of the internet.
x

Everything you need to know about SMTP (Simple Mail Transfer Protocol)

We send emails to one another all the time—a whopping 306.4 billion emails are sent and received every day. It’s one of the most common communication methods for businesses and individuals alike, but have you ever stopped and wondered what goes on after you click “send”? How does your message go from you to your recipients?

There’s a complex process going on behind the scenes to get your emails where they need to be. At the center of it all is an email protocol known as SMTP that’s critical for sending emails… and you’re about to learn everything you need to know about it.

What is SMTP? #

SMTP, which stands for Simple Mail Transfer Protocol, is an email protocol used for sending email messages from one email account to another via the internet. 

Email protocols are sets of rules that let different email clients and accounts easily exchange information, and SMTP is one of the most common ones alongside POP and IMAP. It is also the only dedicated protocol for sending emails. Most email clients—including Outlook, Apple Mail, Gmail, and Yahoo Mail—rely on SMTP to “push” or send messages from a sender to a recipient.

What is an SMTP server? #

Like all servers, an SMTP server is an application that provides a service to other applications within a network, called clients. Specifically, an SMTP server handles the sending, receiving, and relaying of email. 

You can think of servers as your real-life post offices. When you send a letter from city A to city B, it first reaches a local post office in city A; here, it gets processed and sent on the post office in city B, which is in charge of delivering it to its final destination.
The same happens with SMTP servers—though instead of taking days, the process takes a few minutes at most.

How does SMTP work? #

The best way to explain how SMTP works is to go over the sending process, the individual rules and commands that power it, and the errors you may encounter. Fair warning: This is where things start to get technical. Still, we’ll do our best to condense this protocol down into easy-to-digest chunks.

Once an SMTP server is established, email clients can connect to and communicate with it. When the user hits “send” on an email message, the email client opens an SMTP connection to the server so it can send. (The SMTP connection is built on something called a TCP connection, which stands for Transmission Control Protocol.)

From there, the SMTP client uses commands to tell the server what to do and transfer data, like the sender’s email address, the recipient’s email address, and the email’s content. The Mail Transfer Agent or Message Transfer Agent (MTA) checks to see if both email addresses are from the same email domain, such as gmail.com:

  • If they are, it sends the email right away
  • If not, the server uses the Domain Name System (DNS) to identify the recipient’s domain and then send it to the right server.

You don’t need to get into the weeds of SMTP to start sending emails. Postmark’s SMTP email service can handle it all for you and getting started is as simple as copying some credentials into a config file.

Learn more →

Basic SMTP commands #

As we mentioned earlier, SMTP commands are a set of codes that power the transmission of email messages between servers. Here are the basic SMTP commands you should be aware of:

  • HELO or EHLO (Hello): This is a crucial command for beginning the entire email sending process. The email client is identifying itself to the SMTP server. It is the beginning of a conversation and usually involves the server sending a HELO command back complete with its domain name/IP address.
  • MAIL FROM: Following the identification command, the sender will share code that specifies who the mail is from. This outlines the email address and tells the SMTP server that a new transaction is about to start. From here, the server resets everything and is ready to accept the email address. Once accepted, it will reply with a 250 OK reply code.
  • RCPT TO (Recipient To): The next command follows the 250 OK reply code identifying who the email is being sent to. Again, the SMTP server responds with the same code, at which point another RCPT TO command can be sent with a different recipient’s email address. This can go back and forth as many times as required depending on how many people will receive the email.
  • DATA: This triggers the transfer of data between the client and the server. All of the message contents will be moved to the SMTP server, which will respond with a 345 reply code. The contents of the messages are transferred to the server, where a single dot is sent in a line by itself to signal the end of the message. If accepted and ready for delivery, the server sends another 250 OK code. At this point, the message is on its way to the recipients.
  • QUIT: When the email has been sent, the client sends the QUIT command to the server, severing the connection. If it has been successfully closed, the server will reply with a 221 code.
  • RSET (Reset): This command is sent to the server when the mail transaction needs to be aborted. It doesn’t close the connection, but it does reset everything and remove all previous data about the email and the parties involved. You will commonly use this when there has been an error, like inputting the wrong recipient information, and the process needs to be restarted.

Picture these commands as the language that allows email servers to have a conversation with each other. Their chat will look somewhat like this:

overview of SMTP commands

There are other SMTP commands that handle authentication and enhance security, such as AUTH and STARTTLS. If you’re interested in learning about them or seeing examples of SMTP at work, read this guide to SMTP commands.

Understanding SMTP error codes #

The email sending process doesn’t always go as smoothly as in the example chatter of our email servers above. Bounces, blocks, or other issues might prevent an email from being sent. In this case, the receiving server can notify you of issues using SMTP error codes, and knowing what they mean helps you diagnose and fix email delivery roadblocks.

For example, here are two groups of SMTP errors that crop up often:

  • 4.X.X Persistent Transient Failure: These error codes start with the number “4” followed by two other numbers. They typically mean that there’s a temporary failure with the mail server. Repeating the command again could get rid of the error, but these codes are often used by servers to keep untrusted senders at bay.
  • 5.X.X Permanent Error: These error codes begin with the number “5” and are followed by two numbers. They typically signify that the SMTP connection has dropped. If you try to resend the email, it will likely still result in the same error.

PS: if you’re interested in learning more about SMTP errors, here at Postmark we started a public SMTP Field Manual to document the error codes we see most often. Check it out! You can even contribute your own entries if you’ve spotted an SMTP error we haven’t encountered before.

SMTP Field Manual

How is SMTP different from other email protocols? #

Cast your mind back to the definition of SMTP, and you’ll remember we said that it was one of many email protocols. POP and IMAP are the other two most common email protocols in use.

The main difference between these protocols is that SMTP is the only protocol for sending or “pushing” email from one unknown mail server to another. POP and IMAP are protocols for receiving or “pulling” mail for the recipient from their own mail server. So, POP and IMAP limit the transfer of mail to verified mail servers only. They can’t be used for communication outside of your own networks.

Different protocols in the sending process: SMTP is used to send email, POP and IMAP to receive mail

Below, we’ll give you a deeper explanation of how POP and IMAP work and how they differ from SMTP.

POP #

POP stands for Post Office Protocol, and it’s used to receive incoming messages. The most current version is POP3, last updated in 1988.

This protocol gets its name because it operates like a real-life post office in the digital realm. POP3 will receive emails and hold them for clients until they pick them up. All emails are downloaded and stored locally, making it a handy solution for someone who only uses one computer to check emails. It’s also commonly used by businesses so employees can check emails while offline.

How do POP and SMTP differ?

  • SMTP is a message transfer protocol, while POP is a message access protocol. In other words, SMTP is used to send mail from one user to another, while POP is used to receive emails.
  • SMTP is used twice: Once when establishing the connection and sending information between the sender and the email server, and a second time when sending information and connecting to the recipient. POP is only used once between the receiver and their mail server.

IMAP #

IMAP stands for Internet Message Access Protocol. In short, IMAP stores messages on an email server, but this server can be accessed by the user to check and configure their emails. The difference between this and POP is that IMAP uses a cloud server so emails can be authenticated and categorized by any device. Many email users prefer IMAP to POP because of the convenience and efficiency.

If you’ve ever set up your own email client, you probably encountered IMAP on an interface like this one:

Setting up IMAP in Outlook

How do IMAP and SMTP differ?

  • SMTP is a message transfer protocol, while IMAP is a message access protocol (like POP). So while SMTP sends messages and handles outgoing email, IMAP only retrieves messages and handles incoming email.

Running your own SMTP server vs. using a third-party email service: What’s best? #

When it comes to setting up and using an SMTP server, there are two main options:

  • Run it yourself
  • Use a third-party service

What’s the best option? There’s no black-and-white answer, as it all depends on your needs and resources. Below, we’ll take a look at both and highlight the pros and cons of each so you can determine which path to go down.

Running your own SMTP server: Pros and cons #

What sort of advantages or disadvantages can you see from setting up and running your own SMTP server? Here’s an overview, plus a bonus step-by-step guide to SMTP setup and authentication for a more detailed rundown.

  • Pro: No sending volume limits. Many email service providers and internet service providers (ISPs) limit your daily emails, as do some web hosts. When you have your own dedicated SMTP, you can send as many emails as you need on an hourly or daily basis.
  • Pro: Fully monitor email delivery. No matter what happens to your email after you hit send, you will receive helpful delivery information. You can see if your messages were sent to the recipient and examine any error codes.
  • Pro: Your email list is private. Another advantage of running your own SMTP is that you don’t have to share email list information with anyone, maintaining your company’s and your customer’s data privacy.
  • Con: Can take more time, money, and effort. Running an SMTP server requires a lot of resources: you’ll constantly need to monitor that everything is up and running, and may even need to hire a dedicated specialist or team—and that’s after you set up the server itself, which is a whole other story. For many businesses, this is simply too costly.
  • Con: It’s local. Another disadvantage to running your own SMTP server is that it’s local, so it will be vulnerable to power outages or internet connectivity issues in your area. You can set up backup servers and failsafe protections, but again, this requires technical know-how.
  • Con: You might experience deliverability and security issues. Unless sending to specific/limited receivers, it will take time to get the deliverability just right, especially when your email volume changes. Plus, you’ll have to protect your email server from unauthorized access and spam—and that can be a real challenge. That’s the big advantage of using a third-party service: they already have all of that stuff figured out, and have specific processes for detecting when adjustments are needed.

Speaking of which...

Using a third-party email service: Pros and cons #

Now, admittedly we are going to be a bit partial here, because at Postmark we do run a super-reliable email platform that you can use to deliver email via SMTP. This said, we also know that Postmark and other third-party services are not for everyone—so here is a list of the advantages and drawbacks of opting for a third-party email service.

  • Pro: Significantly less hassle for you. Using a third-party email provider takes care of everything for you. You don’t need to have significant technical knowledge or spend time maintaining and monitoring your email server, and you can often tap into technical support to help with any issues.
  • Pro: More secure. Most third-party providers offer multiple backup options to keep your emails safe if one server goes down. They also keep their security in line with the latest industry standards, ensuring your data is safe and secure at all times.
  • Pro: More cost-effective. Paying for a service that you’ll use all the time means you never have to deal with email servers yourself. This can save your business time and money, since you won’t need to employ anyone to monitor and maintain your server or spend money fixing deliverability and security issues. 
  • Pro: More reliable deliverability. Third-party services have long-standing relationships with ISPs and mailbox providers, are experienced when it comes to solving issues and adjusting to the unique requirements of various receivers, have all of the monitoring and delisting processes in place, and of course have plenty of deliverability experts on staff—so you don’t have to worry about any of it.
  • Con: Reliant on others. One of the only drawbacks to using a third-party SMTP setup is that you have to rely on another company if you run into issues with your email server. So if you go down this route, make sure to pick a service and team with great domain expertise—and who make great customer support a priority.

Pro tip: you can check the reputation of your provider on review sites like G2 or by checking out conversations on Twitter and other social channels. Real feedback from actual product users might give you a good idea of what to expect.

Tweet: Oh, what a joy is working with @postmarkapp

Aww. Thanks Val. 💛

  • Con: Dealing with third-party terms and conditions. Finally, you’ll have to abide by the provider’s terms of service (TOS), which could include limits on the number of emails you can send. That said, it’s rare to find a TOS that will significantly reduce or impact your sending volume, whether it’s transactional email or promotional email.

Overall, opting for a third-party email service is the easiest and most reliable way to go for most businesses. It equals fewer risks and fewer headaches, allowing you to focus on your email strategy and send emails without worrying about the technical side of things.

Choose an email service you can count on #

Here’s the bottom line: The world’s email runs on SMTP, and while you can definitely set up your own SMTP server, it may end up being a bigger challenge than it needs to be—particularly if you have no prior knowledge of the inner workings of email protocols, don’t have a lot of resources, and are concerned about security. And even though here at Postmark we’re all excited about designing the perfect email infrastructure, we understand that most normal humans would rather not deal with it.

Most of the time, finding a third-party email service is the best bet, and if you choose Postmark you’ll have an email service you can truly count on. Our SMTP servers are distributed around the globe, giving you access to easy and secure email delivery at all times. And because we have serious street cred with inbox providers, we’re getting your emails delivered fast and reliably.

Ready to start sending?

Sign up for Postmark today and enjoy a free trial on us.

Start a free trial → No credit card required

Learn more about SMTP sending with Postmark:

This post was originally published Jul 27, 2021

Still have questions?

  • Abdullah Al-hennawy Abdullah
  • Anita Pericic Anita

Ask us anything! We’re eager to help you with any problem or question you have…

Schedule a call