Ever wondered how Emails actually work, When you send an email and within a few seconds they are in your recipient’s Inbox, the technology behind how this happens is Simple Mail Transfer Protocol ( SMTP ). How emails are stored on the server once received using IMAP/POP3 Server is a story for a different time, for now, we will cover SMTP and by end of the article, we hope you have a complete understanding of the STMP Protocol, SMTP Servers, Common options and how to ensure your emails done land up in SPAM.
What is SMTP ?
Simple Mail Transfer Protocol ( SMTP ) is the protocol used to Send Emails, it defines a common standard so that any SMTP server can communicate with any other SMTP Server or POP3/IMAP server on the internet and they understand each other. You can say it ensures that different entities involved in the transfer of Emails speak a common language.
What is a SMTP Server ?
The SMTP protocol needs to be made available by an application, this application that responds to the SMTP requests for those who wish to send Email or relay EMail is called a SMTP Serve/SMTP Relay. You can break it into two types as given below, both are mostly the same other than the a minor difference –
- SMTP Server : It is the same thing as a SMTP relay but mainly used when the receiver domain is the same as the server domain. These are usually used with free email services like gmail.com , yahoo.com.
- SMTP Relay Server : This is also a Server, but this term is used when the source email and destination email domains are different from the SMTP server domains. An example can be SendGrid or SendInBlue who offer these.These servers are mainly routers for the mail.
Fake SMTP Servers : – These Servers are mainly used for testing by developers, they basically are catch-all servers that allow users to see how the Email will look on the recipient end without actually sending any Email. You can either install local application like MailHog or MailCatcher or use a cloud on provided like Mailtrap or Our local tool.
How SMTP Works ?
Below is a common guide to how the process of Sending Emails work with the SMTP.
- A user wanting to send an email from say [email protected] to [email protected] uses his Email client to draft an Email with Subject and Body and press Send.
- Once the user presses send the Email client will connect to the configured SMTP server for now let’s assume it to be smtp.source.com . The client and SMTP server do a handshake and if authorization is required then the client will provide credentials for the same.
- After handshake the Email Client sends the Receivers address which in our case is [email protected] , subject and the body.
- If it had been our user had been sending to a someone in the same domain then our server will simply forward it internally to the local recipient server.
- Next the SMTP server using a DNS request for MX records finds out the recipients IP or domain address where his SMTP server is running.
- Next it connects to the receivers SMTP address and tried to deliver the email.
- The recipients Email Server verifies if it can handle the Email being forwarded to it. And if all is well then it forwards this to the incoming IMAP or POP3 Server.
Common SMTP Port and Address
In most cases the SMTP address will be a prefix of mail or smtp in front of the domain to which you are trying to connect to. Also these are specified by the Mail Exchange (MX) records in the DNS which direct a client to the mail server which is supposed the handle how Email messages are to be routed.
To find the address of the SMTP server you can use the dig command
root@mailtest:~# dig +short freesmtpservers.com MX
Then you can use the dig command to find the IP address if required
root@mailtest:~# dig +short smtp.freesmtpservers.com
Things are not so simple with the port which to connect to, Servers and relays usually have a set of different ports which you can connect to, each has come into being overtime to fulfill specific requirements.
|25||Standard SMTP Port||It should mainly be used for Email Relay|
|465||Deprectared SMTP Port||Was for secure SMTP, Used SSL for encryption. Avoid usage.|
|587||Modern Secure SMTP Port||Most moden Email Clients will use this , it uses TLS Encryption.|
|2525||Alternative Non Standard SMTP Port||This is used as an alternative to 587 incase its blocked.|
In most cases you will be using the Port 587 for your needs.
Common SMTP Server Names
Common addresses for SMTP servers start with smtp. or mail. with the domain name, Some might have an IP address also. We have listed a few common ones with their details below –
|Service Name||SMTP Server||Port|
|Yahoo Mail Plus||plus.smtp.mail.yahoo.com||465|
|O2 Online Deutschland||mail.o2online.de||25|
|Verizon (Yahoo hosted)||outgoing.yahoo.verizon.net||587|
|[email protected] by USA.NET||smtp.postoffice.net||465|
Bulk SMTP Server provider settings
What happens if you want to send more than a few Emails, say 10000 K emails then you will need something like a Bulk SMTP relay, they will also provide you API and other features like Delivery tracking, Open rates etc. Also help you send the Emails quite fast as SMTP as a protocol is a bit slow.
If the number is not very large then you can use our listing for Free SMTP Servers providers to make a choice.
If you want to send an email to your large userbase or maybe for Email marketing we have given pricing below with various providers listed.
|Vendor||Free / Month||Daily Limit||Paid plans||Comments|
|SendInBlue||9000||300||$25 for 10k to $499 for 1 Million||Best Free|
|TurboSMTP||6000||200||14.95 for 50k to 979.95 for 2 Million.||6000 / month for 12 months|
|Alibaba Direct Mail||6000||200||.00029 per 1000 Emails|
|PepiPost||3000||100||$25 for 150k to 445 for 2 Million|
|SendGrid||3000||100||$14.95 for 50K emails to $749 for 150K|
|SparPost||3000||100||$20 for 50K to $525 for 1M|
|Elastic Email||3000||100||Costing like Amazon SES||Low cost paid option|
|Amazon SES||62000||.0001 for 1000 Emails||One of the Cheapest , Free if sent from AWS EC2 server|
|GMail||15000||500||Gsuite is the premium option||Domain will be gmail.com , Can lead to account suspension.|
Using a SMTP server with WordPress
WordPress powers almost 40% of the sites on the internet, by default it uses PHP Mail to send transactional emails which inturn if not configured uses sendmail , This can be a hit or miss in the case when delivery is concerned, so we recommend using a WordPress plugin which can use SMTP Settings or use SMTP API for the same.
By default, WordPress uses PHP mail to send an email, if configured correctly it is sufficient, but in most cases, it’s easier to use third-party Service as most shared hosts do not allow direct console access to check what is going on and your Host IP might have been blacklisted due to SPAM as there may also be other users on the Server ( Incase of Common Shared Hosting) who might not behave and cause your IP to be blacklisted. By being blacklisted we mean that your server’s IP is put in a global list of known spammers, which makes it even harder for your Mails to get through, you can check your status here.
For WordPress we recommend the Wp Mail SMTP Plugin, it’s easy to configure, set up, and supports a lot of different vendors including Gmail, there is also an option to log all sent emails. The free plan should be sufficient for most users.
You can easily install it from inside WordPress or even download it from WordPress’s website. It has a premium plan, but free should be good enough for most users.
Setup self-hosted SMTP Server on Linux
Quick MTA Comparison , we will choose Postfix as we will be working with linux –
|if you are...||qmail||Exim||Sendmail||Postfix|| Notes
| Inexperienced||0||3||1||3|| Exim and Postfix have good docs and clear examples
| Worried about security||3||2||0||3|| Postfix is secure and modern; qmail is secure but very old and cranky; Exim is secure to different criteria (read above.)
| Relying on Sendmail milters||0||1||3||2|| Postfix can run milters; can use equivalent Exim routers/filter script
| Wanting minimum hassle||0||3||0||3|| Sendmail has some easy front-ends, but the deeper you go the worse it gets. Postfix and Exim are more predictable.
| Resource-constrained||3||2||1||2|| See Embedded Application below for other comments
| On Windows||0||2||3||0|| Sendmail has a native Windows port; Exim is in the Cygwin distro
| Needing commercial support||1||3||3||3|| There are competent companies for all MTAs; qmail is inherently less supportable being so old
Postfix is a Mail Transfer Agent (MTA) that can act as an SMTP server or client to send or receive email. It is easy to set up and configure and we ourselves use it for most of our needs , it can also be setup to act as an intermediary to forward emails through third-party emails services. We will only cover basic setup and send your first email.
The most simple setup consists of installing postfix and you should be good to go.
Such a bare-bones setup will work technically but your Emails might land in SPAM, to cater to this and ensure better email deliverability, we have another guide where we add the other requirements like DKIM or SPF which are needed to make sure your Emails go through. But still, unless there is a very good reason we do not recommend to run your own Email Server.
This process assumes that you have a new installed Ubuntu 20.04 and you can work with command line Linux , if not we recommend using one of the existing SMTP Providers. We will set up postfix on Ubuntu 20.04 server and send an Email using it to our very own dummy service for testing to see if it works.
To begin we will issue the update cache command for apt package manager
sudo apt update
Next we will install postfix using the following command –
sudo apt install postfix
The installation will open up a bunch of prompts please make the following selections –
- General type of mail configuration? : For this, we will choose an Internet Site since this matches our infrastructure needs.
- System mail name: This is the base domain that will be used to send an email if no sender domain is specified by the user. So if you send an email from say user1 and no domain is specified this will be postfixed to the email. So if example.com is given, it will send email from [email protected] .
That should take care of the basic config. For a complete setup please follow our mail-server setup guide. Now port 25 should be available, you can check f its open by using any of the commands –
sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN
sudo ss -tulpn | grep LISTEN
sudo lsof -i:22 ## see a specific port such as 22 ##
sudo nmap -sTU -O IP-address-Here
What we are looking for something like this
master 2575 root 13u IPv4 30244 0t0 TCP *:25 (LISTEN)
master 2575 root 14u IPv6 30245 0t0 TCP *:25 (LISTEN)
If you even need to reconfigure the setup simply run the command –
sudo dpkg-reconfigure postfix
We are all set our SMTP server should be up and running. Next, we can be sending an Email to some users on the internet or maybe to catch all email to test things.
Using a SMTP Server
Usually, an Email client is the most common way most of us will interface with an SMTP server , but you can also directly interact with it using telnet. We will start with this method as it is just plain cool.
Send mail using telnet in linux
Connect to your local SMTP Server by entering the following command –
telnet localhost 25
You will see something like this –
root@mailtest:~# telnet localhost 25
Connected to localhost.
Escape character is '^]'.
If you are not able to connect make sure postfix is running and check port 25 is open.
Now lets send a email to say [email protected] ( catch all email ).
root@mailtest:~# telnet localhost 25
Connected to localhost.
Escape character is '^]'.
220 mailtest ESMTP Postfix (Ubuntu)
250 2.1.0 Ok
250 2.1.5 Ok
354 End data with .
Subject:Testing Email service
This is a test email.
250 2.0.0 Ok: queued as A6ADC402D4
221 2.0.0 Bye
Connection closed by foreign host.
Go check if the Email is received in the inbox for [email protected], or if you used a different recipient can check it in its inbox.
Send Email from linux command line
On linux we can use the sendmail command to send Email quickly.
echo "Subject: hello" | sendmail -v firstname.lastname@example.org
I hope you like my article, if you feel i missed some points or was wrong somewhere then please do let me know and I will update it here.