Is it hard to send an email? From a user’s perspective, everything looks quite simple. Under the hood, however, there is a complex system that drives emails from the sender to the recipient. When you click a button to send an email, your email client connects to the mail server. Servers are computers that handle specific services. A mail or email server is meant for dealing with emails. At the same time, we can break down email servers into two categories: outgoing and incoming. Today, we’re talking about a concept related to an outgoing mail server, known as an SMTP server.
An SMTP server is a computer or an app that is responsible for sending emails. It functions following the Simple Mail Transfer Protocol (SMTP). An SMTP server receives emails from the email client. Then it passes them on to another SMTP server and relays them to the incoming mail server.
- What is the difference between an SMTP server and an IMAP/POP3 server?
- How an SMTP server works
- What is an SMTP server address?
- How an MTA differs from an SMTP server?
- Is an SMTP server and an SMTP relay the same?
- Should I choose a local or cloud-based SMTP server?
- What is a fake SMTP server?
- SMTP relay server or HTTP API – which one is better and when?
- SMTP server troubleshooting checklist
- To wrap up
What is the difference between an SMTP server and an IMAP/POP3 server?
SMTP is an email sending protocol, whereas IMAP4 and POP3 are protocols to receive emails. Therefore, an incoming mail server may use one of those protocols for email delivery. Here is how they work:
|IMAP workflow||POP3 workflow|
The main difference between these protocols is that IMAP servers always store copies of emails, while POP3 servers delete them once they are retrieved. For more on the Difference Between IMAP, POP3, and SMTP Email Protocols, read our blog post.
How an SMTP server works
Take a look at the basic steps of email sending and what role the SMTP server plays.
- A mail user agent (MUA), which can be your email client or an app, connects to the SMTP server of your domain (for example,
smtp.mailtrap.io). This is called an SMTP handshake. The connection is carried out via an SMTP port, which is normally 25. But there are other options you can learn in our blog post about SMTP ports. Once connected, the SMTP session begins.
- The client submits the sender’s and recipient’s email addresses, as well as the email body and attachments, to the server.
- The SMTP server, or more precisely the mail transfer agent (MTA), checks whether the domain name of the recipient and the sender is the same. If it is, the email goes directly to the recipient’s POP3 or IMAP server. If the domains are different, the SMTP server has to communicate with the Domain Name Server (DNS).
- The DNS provides the recipient’s IP address.
- The sender’s SMTP server connects to the recipient’s SMTP server and relays the email. If the recipient’s server is not available (down or busy), the email will be put into an SMTP queue. This is a buffer where the emails are stored before they hit the endpoint. For more on this, read What is an email queue? Alternatively, the email can be dropped to a backup server.
- The recipient’s SMTP server verifies the incoming email. If the domain and user name has been recognized, the server forwards the email to the POP3 or IMAP server.
What is an SMTP server address?
An SMTP server has a web address to communicate with other servers and clients on the Internet. Usually, it looks like
mail. plus the domain name. For example,
mail.gmx.net. If you’ve set up a local SMTP server, you can use its IP address, let’s say,
127.0.0.1, instead of the web address.
Users of shared email services can find information about the SMTP server address by looking up the MX records of the domain.
How an MTA differs from an SMTP server?
It is common practice to use the term “mail transfer agent ” instead of “SMTP server”. But aren’t these notions different? An MTA is software installed on the SMTP server. Generally, an MTA receives emails from an MUA and forwards them to:
- a mail delivery agent (MDA), if the sender and the recipient has the same domain, or
- another MTA (SMTP server)
In some cases, there could also be a mail submission agent (MSA) between the MUA and MTA. However, many MTAs carry out the MSA function, that’s why the mention of mail submission agents is often omitted. The most used MTAs are Postfix, Sendmail, and Exim.
So, if you name the SMTP server an MTA or even an MSA, this won’t be a mistake. The difference lies in the nomenclature you use.
Is an SMTP server and an SMTP relay the same?
SMTP relay is the process of transferring emails between SMTP servers (or MTAs if you will). Relay happens if the sender and the recipient come from different domains. In practice, however, the term SMTP relay often refers to SMTP servers that enable relaying. Email providers like Mailgun offer such relay servers for bulk email and transactional email sending. In this context, we can say that an SMTP server and an SMTP relay are the same thing.
Should I choose a local or cloud-based SMTP server?
In the article Best Free SMTP Servers, we introduced a list of cloud-based options that most startups and projects opt for. These include Gmail, Amazon SES, Elastic Email, and others. The main benefit of using one of those is that you don’t have to build and maintain the whole email environment. This means you save your resources.
A local SMTP server might be an option as well. It imposes no limit on how many emails you send per hour/day and ensures control of all your outgoing mail. However, this comes with a drawback as the bounce rate can increase by 20-30%, which is a major consideration for deliverability. If you want to know how to set up a local SMTP server, check out this blog post.
What is a fake SMTP server?
- A real SMTP server accepts emails from the client and sends them to the incoming mail server.
- A fake SMTP server accepts emails from the client and emulates sending without actual delivery.
Why would I need a fake one then? – For testing email sending, of course!
At a certain stage of your project, you’ll need to send a couple of test emails from your app or website. You can do this using a real SMTP server. In this case, you would have to tinker around with dummy email addresses unless you want your test emails to hit the inboxes of real customers. But using dummy email for testing just doesn’t work. That’s why a fake SMTP server comes into play!
Mailtrap.io represents a cloud-based service with a fake SMTP server under the hood. You send test emails from your app and Mailtrap catches and puts them into a virtual inbox. You can be sure that none of the emails will get to a real user. Additionally, you can preview the content of the emails, check them for spam and much more. For more on the available features, read the Mailtrap Getting Started Guide.
You may also consider setting up a local fake SMTP server like MailHog or MailCatcher or even a desktop app, for example, FakeSMTP or DevNull SMTP. We described the reasons to choose between cloud-based and local fake SMTP options in the dedicated blog post.
SMTP relay server or HTTP API – which one is better and when?
A mail user agent (the client) sends emails to the server via SMTP. It is a platform-agnostic protocol widely used for sending emails. At the same time, you can send emails from your app using a web-specific protocol – HTTP. In this case, there are no client-server or server-server back-and-forths. Your app sends HTTP requests to a third-party service that performs email sending. This way of mail delivery is known as HTTP API or Web API.
We can’t claim that Web APIs exceed the service of SMTP relay servers. Each option has its pros and cons:
|Web API||SMTP relay server|
Pick an SMTP server if:
- you prefer simplicity for basic tasks
- you need integrability with your CRM system or mail client
- you’re looking for a reliable and sustainable solution
Pick Web API if:
- you deal with bulk emails
- you need expanded functionality
- you don’t mind tinkering with code
For more about differences between SMTP relay server and HTTP API, read our blog post.
SMTP server troubleshooting checklist
Let’s say you’ve checked the email sending of your app and it’s alright. We hope that Mailtrap helped you with that :). But when you started using a real SMTP server for sending emails, they were not delivered. The following checklist will help you detect what may be wrong:
- check the Internet connection
- check the SMTP server configuration (server name, port, username, password)
- try different SMTP ports
- test the SMTP server connection. For this, you can either use an online service like MXToolbox or perform a manual telnet session. Read our blog post about testing SMTP server to learn how to do this. You may also need to know SMTP commands and response codes for troubleshooting.
To wrap up
An SMTP server is your digital postman, which either delivers your emails right to the recipients’ mailbox or hands them over to other postmen out of your domain. Keep in mind that SMTP servers deal with outgoing mail only. For incoming emails, you’ll need another type of mail server – IMAP or POP3. We’ll talk about them in one of our next blog posts. Stay tuned with Mailtrap!