Tutorial Set up new Postal open source mail server (v. 3.x)

prashannaprashanna is verified member.

Administrator
Staff member
Joined
Mar 7, 2024
Messages
11
Reaction score
1
Yesterday, I was setting up this new version of the Postal mail delivery platform on my server, and I wanted to familiarize you with the process of setting up a mail server. So, let's get started.

First, you can start with the documentation. The team suggests a dedicated server with at least 4 GB of RAM, 2 CPU cores, and 25GB of storage for the postal mail. These requirements may scale according to your usage.

You also pre-require docker. To install that, we need to add the Docker GPG key and the repository to the Docker for apt to install.

Code:
apt-get update && apt-get upgrade

sudo apt-get install ca-certificates curl gnupg lsb-release

sudo mkdir -m 0755 -p /etc/apt/keyrings

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Once again, you need to update apt-get repositories to reflect new changes.

Code:
apt-get update

Finally, you can install Docker.

Code:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin


After this, try running `docker compose`. It should work. If not, you may install Docker Compose separately. Run the following commands:

Code:
curl -SL https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

Code:
sudo chmod +x /usr/local/bin/docker-compose

Code:
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Now, `docker-compose` with the minus (-) should do the job.

Another set of requirements are the Git, cURL, and JQ packages.

Code:
sudo apt install git curl jq

Last but not least, we need MongoDB to save all the data and mail. For that, either you can manually set up a MongoDB server, or you can run this one command:

Code:
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

Change the MARIADB_ROOT_PASSWORD to your own password, and that's all for the prerequisites. The command will run a local MariaDB inside a Docker container with the database named postal (you can change it) and the password that you set up, which is self explanatory.


Installation

Using git, pull the postal email repository into opt, then symlink it to the bin.

Code:
git clone https://github.com/postalserver/install /opt/postal/install
sudo ln -s /opt/postal/install/bin/postal /usr/bin/postal

Now, you can go ahead and initialize the postal service and run it in your host. But wait, first you need to set the configurations. To make the process easier, the documentation suggests creating a bootstrap config file and editing from there.

Code:
postal bootstrap postal.domainname.com


Replace postal.domainname.com with your subdomain.domain.tld. I recommend you use the postal subdomain for most of the parts, but you can always switch it up. Then, edit the config file located at /opt/postal/config/postal.yml to cater to your needs. Minimally, you can only update the password of the MongoDB to whatever you put in the previous stage. Then initialize the service, and also create an admin user for the backend.

Code:
postal initialize
postal make-user

Type in whatever it asks you: admin email, first name, last name, and password. At last, you can end it all with a start command.

Code:
postal start

If you are trying to serve the mail with HTTPS and TLS enabled(which you should), you need to add tls email@domain.tld inside the Caddyfile under subdomain.domain.tld {. And then, run the Caddy web server for the backend using:

Code:
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


Oh, and also set an A record, or reverse proxy, pointing to your IP address. Request your VPS provider, or if you have a dedicated server, add it yourself. To add hostname to the server, run these commands:

Code:
sudo hostname postal.domain.tld
To set the hostname, and

Code:
hostname -f
to check your hostname.


Setup

Finally, you can go to postal.domain.tld and set up a mail server for yourself. First, log in using the email and password you mentioned when using `postal make-user`. Then, create an organization. Set whatever name for the organization and open it. Then, after that, create a web server, set up its name, and change the mode to LIVE. Now we are getting somewhere.

After entering the web server, go to domains in the navigation bar and create a new domain. The domain should be domain.tld, or subdomain.domain.tld - For eg: if you want the email to be admin@domain.tld, use domain.tld as the domain. The mail server will yell at you for not completing all the requirements regarding DNS records. Do as they suggest, or even better, follow the following table:


NameTypeValue
rp.your_hostname_subdomainAyour_ipv4
track.your_hostname_subdomainAyour_ipv4
spf.your_hostname_subdomainAyour ipv4
your_hostname_subdomainAyour ipv4
psrpCNAMErp.your.hostname.com
@MX10; mx.your_hostname_subdomain.your_domain.com
routes.your_hostname_subdomainMX10; your_hostname_subdomain.your_domain.com
rp.your_hostname_subdomainMX10; your_hostname_subdomain.your_domain.com
@TXTv=spf1 a mx include:spf.your_hostname_subdomain.example.com ~all\
rp.your_hostname_subdomainTXTv=spf1 a mx include:spf.mail.your_domain.com ~all
spf.your_hostname_subdomainTXTv=spf1 ip4:your_ipv4 ~all
postal-......._domainkeyTXTv=DKIM1; t=s; h=sha256; p=MIGfMA0GCSqGSIb3;
_dmarcTXTv=DMARC1; p=reject; sp=reject; rua=mailto:postmaster@your_domain.com
Credit: technicalsahil.com

If you are following along with the tutorial, the subdomain is 'postal', or whatever you set it in the postal.config file.

After you complete setting up DNS records, even though some of them are redundant, you are ready to send emails through this mail server. To test, go to Messages from the navigation bar and then Send Messages. From there, send your email a message, it should work. Also, you need to set up routes to receive mail through it. That's how you create a mail server with a backend for free.
 
Thank you Prashanna. Great tutorial!

Please add to the DNS table:
postal.your_hostname_subdomain A your_ipv4
spf.postal.your_hostname_subdomain A your_ipv4

and, what about the A record for mail.postal.your_hostname_subdomain ? .. is it needed if we use the server for sending email out only? .. not receiving?

Thank you.
 
Note: this task was done to create an SMTP server for DNForum.com > built in 2001, today it has over 500'000 users.

The issue is >> lots of members have emails that don't exist anymore, but the users are still good, and might retirn at some point.

So, when you have at least 200'000 dead emails of a busy forum users who might return after some time (we keep seeing this every month - an occasional OG domain pro contacts us to check their old account and update the email) > there are no 3rd party solutions that will agree to host such a high bounce-rate client as us.

A server for this job: Intel Xeon-E 2136 processor / 6 cores / 12 threads, 64 GB of RAM and 2×4 TB HDD SATA (soft raid).

I made a choice to choose OVH over Hetzner for this server. Hetzner is cheaper, but are more "anal" on any reported problems. I personally think that French are more relaxed than German :) .. and this will be important when we blast out the 1st email newsletter to all the 500+k members.

Questions?

H
 
Helmuts said:
Thank you Prashanna. Great tutorial!

Please add to the DNS table:
postal.your_hostname_subdomain A your_ipv4
spf.postal.your_hostname_subdomain A your_ipv4

and, what about the A record for mail.postal.your_hostname_subdomain ? .. is it needed if we use the server for sending email out only? .. not receiving?

Thank you.

Yes, I have made edits to the original post. I'm not sure, but I think all the A records are redundant except for the hostname_subdomain (postal). I'm afraid to check it, though.

Also, I forgot to remove the mail.postal A record from DNS records. They were useless. You need to set up routes from the backend to get the mail receiving part working in the case of Postal mail server.
 
Back
Top