Building a Postal SMTP server to send bulk emails is a good choice for email marketers. Postal is very powerful and backed by a large community of developers. It is an open-source mail server script written in JavaScript and Ruby. It can be used to build in-house SMTP servers just like Mailgun, Sendgrid, Mailchimp, etc.
Postal installation is not very straightforward. The process is fairly complex. It’s because Postal needs several packages to be installed beforehand, it can be used. I have tried to make it as simple as possible.
Requirement for Postal SMTP server
- A domain name from Namecheap or Namesilo
- A VPS or cloud with a minimum of 4 GB RAM and 2 vCPU
- Operating System: Ubuntu 22.04 or Ubuntu 20.04
I am using Contabo for demonstration.
Initial Setup
To start with installation, you will need to connect to the server. If you are on you have to get an SSH client for this purpose. One such SSH client is Putty. But if you are on Linux or Mac, just open the terminal and type ssh@xx.x.x.xxx where xx.x.x.xxx is your server IP address.
First of all switch to root user
1 | sudo -i |
After that update and upgrade your Ubuntu
12 | apt update -y apt upgrade -y |
Next set up the hostname. Replace “example.com” with your domain name.
1 | hostnamectl set-hostname postal.yourdomain.com |
Updating DNS records
Login to the domain registrar and create A record for mail.example.com
Now let’s begin with the installation.
Installing Docker and Docker-Compose
Recently postal team switched to docker mode to make installation easier for the end users. Therefore we need to install Docker and Docker-Compose first. I already have discussed what is docker, docker-compose & installation steps in detail. Feel free to read the article to have a clear understanding of docker.
Installing Docker
First of all, set a few packages to set up the Docker repository
1 | sudo apt-get install ca-certificates curl gnupg |
Next, add Docker’s official GPG key.
123 | sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg sudo chmod a+r /etc/apt/keyrings/docker.gpg |
Now, you can install the Docker repository using the following commands
1234 | echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null |
Next update the system software
1 | sudo apt-get update -y |
Finally, run the following command to install Docker Engine and containerd.
1 | sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin |
Installing Docker-Compose
First of all download the current stable release of Docker Compose:
1 | curl -SL https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose |
Next, update the permission to binary
1 | sudo chmod +x /usr/local/bin/docker-compose |
Also, create a symlink as well
1 | sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose |
Finally, test the docker-compose installation
1 | docker-compose --version |
You will see the docker-compose version. If you see anything else this means something has gone wrong.
Installing Additional Prerequisites for Postal SMTP
After installation of Docker and Docker-compose, you need to install a few other packages like Git, MariaDB, etc.
So, let’s install them one by one.
First, install git and git curl
1 | apt install git curl jq -y |
Next clone the postal helper repository
12 | git clone https://github.com/postalserver/install /opt/postal/install sudo ln -s /opt/postal/install/bin/postal /usr/bin/postal |
Installing MariaDB
Now, you can install MariaDB in the docker container
1234567 | docker run -d --name postal-mariadb -p 127.0.0.1:3306:3306 --restart always -e MARIADB_DATABASE=postal -e MARIADB_ROOT_PASSWORD=postalpassword mariadb |
Now we have installed all the prerequisite packages, it’s time to install Postal
Note: RabbitMQ is no longer required in current version of postal. Therefore this part has been removed from the article.
Installing Postal
The postal repository, you installed earlier, is capable of generating some configuration files to use
Run the following command.
1 | postal bootstrap postal.yourdomain.com |
The above command generates 3 files. Out of which postal.yml is of our interest.
You need to edit the postal.yml and make changes. But before that install an editor. I suggest installing nano.
1 | apt install nano -y |
Now to edit postal.yml run the following command
1 | nano /opt/postal/config/postal.yml |
You will see output something like this
version: 2 postal:web_hostname: postal.yourdomain.comweb_protocol: httpssmtp_hostname: postal.yourdomain.com main_db:host: 127.0.0.1username: rootpassword: postalpassworddatabase: postal message_db:host: 127.0.0.1username: rootpassword: postalpasswordprefix: postal smtp_server:default_bind_address: “::” dns:# Specify the DNS records that you have configured. Refer to the documentation at# https://github.com/atech/postal/wiki/Domains-&-DNS-Configuration for further# information about these.mx_records:- mx.postal.yourdomain.comspf_include: spf.postal.yourdomain.comreturn_path_domain: rp.postal.yourdomain.comroute_domain: routes.postal.yourdomain.comtrack_domain: track.postal.yourdomain.com smtp:# Specify an SMTP server that can be used to send messages from the Postal management# system to users. You can configure this to use a Postal mail server once the# your installation has been set up.host: 127.0.0.1port: 2525username: # Complete when Postal is running and you canpassword: # generate the credentials within the interface.from_name: Postalfrom_address: postal.yourdomain.com rails:# This is generated automatically by the config initialization. It should be a random# string unique to your installation.
Make sure to modify database passwords in above file. Cross-check other settings and then save and close the file with CTRL + X.
Initializing Database
Initializing Database is super easy, just execute the following command and you will see database tables were getting created in the output.
1 | postal initialize |
After that, it’s time to build postal
1 | postal make-user |
You will be asked for the email id, name, and password of the admin user. Type the answer and then go to the next step.
Starting & Running Postal
Starting and running postal is also super easy. Just run the following command.
1 | postal start |
You can check the status of postal
1 | postal status |
Installing Caddy
This is a new feature added by the Postal team to install SSL automatically.
1234567 | 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 |
Now you can go to https://postal.yourdomain.com
and log in using admin credentials. You will see the admin page something like this.
1
sudo -i