- 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.
Once again, you need to update apt-get repositories to reflect new changes.
Finally, you can install Docker.
After this, try running `docker compose`. It should work. If not, you may install Docker Compose separately. Run the following commands:
Now, `docker-compose` with the minus (-) should do the job.
Another set of requirements are the Git, cURL, and JQ packages.
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:
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.
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.
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.
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.
If you are trying to serve the mail with HTTPS and TLS enabled(which you should), you need to add
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:
To set the hostname, and
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:
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.
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
Code:
hostname -f
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:
| Name | Type | Value |
| rp.your_hostname_subdomain | A | your_ipv4 |
| track.your_hostname_subdomain | A | your_ipv4 |
| spf.your_hostname_subdomain | A | your ipv4 |
| your_hostname_subdomain | A | your ipv4 |
| psrp | CNAME | rp.your.hostname.com |
| @ | MX | 10; mx.your_hostname_subdomain.your_domain.com |
| routes.your_hostname_subdomain | MX | 10; your_hostname_subdomain.your_domain.com |
| rp.your_hostname_subdomain | MX | 10; your_hostname_subdomain.your_domain.com |
| @ | TXT | v=spf1 a mx include:spf.your_hostname_subdomain.example.com ~all\ |
| rp.your_hostname_subdomain | TXT | v=spf1 a mx include:spf.mail.your_domain.com ~all |
| spf.your_hostname_subdomain | TXT | v=spf1 ip4:your_ipv4 ~all |
| postal-......._domainkey | TXT | v=DKIM1; t=s; h=sha256; p=MIGfMA0GCSqGSIb3; |
| _dmarc | TXT | v=DMARC1; p=reject; sp=reject; rua=mailto |
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.