There are several methods to build SMTP servers, in this guide I will build the SMTP server using a free open source software called “Postal“.
Postal is a fully-featured open source mail delivery platform for incoming & outgoing e-mail and gives you all the tools and features needed to build a full mailing system for your business.
What is the SMTP Server?
I don’t like robotic definitions like Wikipedia, I love to make things simple.
Simply, SMTP is that thing that allows you to send emails over the internet.
SMTP stands for “Simple Mail Transfer Protocol”. It’s a Concept in Networking that you don’t have to worry about.
Just Know that SMTP is the technical thing that is responsible for delivering emails over the internet.
Let’s connect things, how this is related to email marketing?
Email marketing system consists of two parts:
- The sender: (SMTP service) this is the technical part. It allows you to send emails over the internet.
- The Management Application, where you can configure and manage your Email Lists, Marketing Campaigns, monitor and analyze results, manage your sending servers, and so on.
So we connect both together to get an Email Marketing System.
What do we mean by Sending Unlimited Emails?
When we say unlimited emails, this means that we can send unlimited emails from our server, there are no restrictions by companies or monthly plans to buy or so.
It’s your own server, u can send as much your server can handle in terms of resources. so when you have more (CPU and RAM), you can send more emails and so on.
Setup the SMTP Server, Let’s Start!
Ok, So Let’s start the real work! but before, you need to know what is required.
Requirements to Setup SMTP Server.
In order to Build and Setup an SMTP Server, you will mainly need two things:
- A Domain name
- VPS Server with port 25 opened.
1. Domain name
When you send emails, you will be sending from an email address like this one:
So in my case, “H-educate.com” is the domain name that I use to send my emails. so simply it’s required to have a domain name to use when you send emails from your SMTP server.
Usually, it’s your website domain name, except if you are working with cold emails, then it’s better to get and use another domain in case it got blacklisted, to keep your main business domain safe.
So if you don’t have a domain yet, go and get one NOW! in order to continue the Setup.
How to get a domain? simply you buy one! and it costs around 11$ per year, so it’s not that big deal!
We have a lot of DOMAIN REGISTRATION PROVIDERS where you can get a domain from like:
- Google Domain.
Here in the course, I will be using Namecheap to get my domain, but you can use any other service if you want, all work in the same way, and if you need any help, I will be here 🙂
2. VPS Server with Port 25 opened.
The second thing you will need is a VPS server. a public server to install & Setup SMTP on.
What is a VPS server?
If you don’t know what is a VPS server, simply its a computer (a server) running in the cloud that you buy from a Web Hosting or Cloud Services company. And it’s publicly accessible with a Public IP.
A VPS can be used to host your websites with higher performance, can be used to run a machine 24/7 in the cloud to do any task you want.
Note: If you are interested in learning how to host your own websites on a VPS server, you can
Anyway, In our case, we will be using the VPS Server for Building an SMTP server.
Port 25 open??
I mentioned that the VPS must have port 25 opened, what does this mean?
I don’t want to bother your head within deal technical stuff but in short. Any network service or software uses a certain port to communicate over the internet or network. Examples:
- Connecting remotely to another Windows Machine using RDP software works over port 3389.
- SQL database systems like MYSQL on our computer works over port 3306.
- Connecting to a Linux machine remotely to manage it with SSH, uses port 22.
- When you surf the web and open websites, we use port 80. and so on.
By default, all servers and computers have a firewall running which blocks all ports except the ones you want. so In order to use a certain service, we need to open that port in the firewall.
So, in our case, we are building an SMTP server, and the SMTP software or protocol communicates over port 25. so we need to have port 25 opened.
So when you get a VPS server, just make sure that the company allows Port 25 an don’t block it, because some companies do this to protect from spammers.
Here is a list of some companies that allows port 25 by default:
- Host wind.
- Digital Ocean*
- AWS (some accounts are blocked)
*Digital Ocean Sometimes block some accounts and restrict port 25, but in general they allow all ports.
Are there any other Companies?? yes, simply you can contact the support of any company you want and ask if they block any ports by default. if not, then perfect, you can go with it.
Feel free to use any VPS company you want, It’s up to you!
After you select your VPS company, just create a VPS Server with the following specifications:
- Ubuntu 18 x64 as your operating system
- You can start with 1 CPU/2 GB RAM (And resize later).
VPS Server basic configuration.
Now we have our new Ubuntu VPS server, Let’s prepare it for out Setup.
First, check your hostname:
If you don’t see a form of ANYTING.YOURDOMAIN.COM, then you need to change the hostname using the following command:
sudo hostname host.domain.tld
Where the host is anything you want. so in my case, my sample domain for this tutorial is mailknock.net, the command will look like this:
sudo hostname postal.mailknock.net
Map your domain name.
Now we have our VPS server and we set its name. Go to your Domain Provider and map your Domain to your VPS server. simply open DNS management zone and add a new A record like this:
Host: Postal points: YOUR SERVER IP.
*postal is in my case, you can choose whatever you want for your server name.
Setup Free SMTP Server
The VPS is ready, and we can start the installation process. So in order to setup SMTP Server on our VPS, we need to install an SMTP software.
Install Postal Free SMTP Software
Postal runs entirely using containers which means to run Postal you’ll need some software to run these containers. We recommend using Docker for this purpose but you can use whatever software you wish.
To install docker, run below commands. (NOTE: Each command starts with a – )
-sudo apt-get update -sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg \ lsb-release -curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg -echo \ "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null -sudo apt-get update -sudo apt-get install docker-ce docker-ce-cli containerd.io -sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose -sudo chmod +x /usr/local/bin/docker-compose -docker-compose --version
There are a few system utilities that you need to have installed before you’ll be able to run some of the Postal commands.
apt install git curl jq
Git & installation helper repository
Make sure you have git installed on the server by running below commands.
-git clone https://postalserver.io/start/install /opt/postal/install -sudo ln -s /opt/postal/install/bin/postal /usr/bin/postal
You can run MariaDB in a container, assuming you have Docker, using this command. Copy and paste this all in Putty.
docker run -d \ --name postal-mariadb \ -p 127.0.0.1:3306:3306 \ --restart always \ -e MARIADB_DATABASE=postal \ -e MARIADB_ROOT_PASSWORD=postal \ mariadb
This will install your postal database on MariaDB.
RabbitMQ is responsible for dispatching messages between different processes. As with MariaDB, there are numerous ways for you to install this. For this guide, we’re just going to run a single RabbitMQ worker. Copy all the below as one command and paste on putty.
docker run -d \ --name postal-rabbitmq \ -p 127.0.0.1:5672:5672 \ --restart always \ -e RABBITMQ_DEFAULT_USER=postal \ -e RABBITMQ_DEFAULT_PASS=postal \ -e RABBITMQ_DEFAULT_VHOST=postal \ rabbitmq:3.8
Run the command below and replace
postal.yourdomain.com with the actual hostname you want to access your Postal web interface at. Make sure you have set up this domain with your DNS provider before continuing.
postal bootstrap postal.YOURDOMAIN.COM
Initializing the database
Run the following commands to create the schema and then create your first admin user.
postal initialize postal make-user
You’re now ready to run Postal. You can do this by running:
This will run a number of containers on your machine. You can use
postal status to see details of these components.
Installing WEB Client
You can use any web client to run postal on your web, but in this guide, we are going to use Caddy. Install it with an SSL using below command.
docker run -d \ --name postal-caddy \ --restart always \ --network host \ -v /opt/postal/config/Caddyfile:/etc/caddy/Caddyfile \ -v /opt/postal/caddy-data:/data \ caddy
Once this has started, Caddy will issue an SSL certificate for your domain and you’ll be able to immediately access the Postal web interface and login with the user you created in one of the previous steps.