Having a fully featured email solution is a basic requirement of any business, institution or company. Here we will discuss the installation of Postal Mail delivery solution on Ubuntu 22.04|20.04|18.04. Postal is a mail delivery platform for both incoming and outgoing emails. It is a complete and fully featured mail server that should satisfy all your websites & web servers email requirements.
The minimum specification for Postal is as follows:
- At least 4GB of RAM
- At least 2 CPU cores
- At least 100GB of disk space
Install Postal Mail Server on Ubuntu 22.04|20.04|18.04
The installation of Postal Mail Server on Ubuntu is not as complicated as others say. By sparing some minutes and following below few steps, you should have Postal Mail Server running on Ubuntu 22.04|20.04|18.04 server.
Step 1: Update your system
Like all other installation guides available on ComputingPost, we start the installation by ensuring our system is updated.
sudo apt update
sudo apt -y upgrade
Perform a reboot if it is required:
[ -f /var/run/reboot-required ] && sudo reboot -f
Then install git once the system is up
sudo apt -y install git jq
Step 2: Install Docker & Docker Compose
Import Docker repository GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg
With GPG key imported you can add Docker repository to your Ubuntu system.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Finally install Docker CE on Ubuntu 22.04|20.04|18.04:
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
Add your user account to docker group.
sudo usermod -aG docker $USER
newgrp docker
Confirm successful installation by checking Docker version
$ docker version
Client: Docker Engine - Community
Version: 20.10.16
API version: 1.41
Go version: go1.17.10
Git commit: aa7e414
Built: Thu May 12 09:18:18 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.16
API version: 1.41 (minimum version 1.12)
Go version: go1.17.10
Git commit: f756502
Built: Thu May 12 09:16:22 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.4
GitCommit: 212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
runc:
Version: 1.1.1
GitCommit: v1.1.1-0-g52de29d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Install Docker Compose:
Step 3: Install MySQL / MariaDB database server
The other requirement of Postal Mail server is a database server.
sudo apt install mariadb-server
Also install libmysqlclient-dev
sudo apt install libmysqlclient-dev
After installation of MariaDB/MySQL database server, create a user and database for Seafile.
First login to MySQL shell as root user:
$ sudo mysql -u root -p
Enter password: <ENTER>
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 31
Server version: 10.6.7-MariaDB-2ubuntu1 Ubuntu 22.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
We will create a database for each of these server components.
CREATE DATABASE postal CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;
Create a database user and grant privileges for created databases.
CREATE USER 'postal'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT ALL ON postal.* TO 'postal'@'localhost';
Postal will handle the creation of databases for your mail servers but you need to give it access to do this. Allow postal
user to manage all databases that are prefixed with postal-
.
GRANT ALL PRIVILEGES ON `postal-%`.* to `postal`@`localhost` IDENTIFIED BY "StrongPassword";
FLUSH PRIVILEGES;
QUIT
Confirm access by Logging into the database as postal
user:
$ mysql -u postal -p'StrongPassword'
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.6.7-MariaDB-2ubuntu1 Ubuntu 22.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| postal |
+--------------------+
4 rows in set (0.001 sec)
MariaDB [(none)]> QUIT
Bye
Step 4: Install and Configure RabbitMQ
Postal uses RabbitMQ for queueing. Install RabbitMQ on Ubuntu using the link below:
You can skip the section of configuring RabbitMQ Management Dashboard and Set RabbitMQ Cluster. A single node RabbitMQ installation should be enough for small usage.
Postal requires its own RabbitMQ vhost and user to connect with. You can create these using the following commands:
sudo rabbitmqctl add_vhost postal
sudo rabbitmqctl add_user postal StrongPassword
sudo rabbitmqctl set_permissions -p postal postal ".*" ".*" ".*"
Step 5: Install and Configure Postal on Ubuntu 22.04/20.04/18.04
Cloning the Postal repository
sudo git clone https://postalserver.io/start/install /opt/postal/install
Create a symlink for Postal binary.
sudo ln -s /opt/postal/install/bin/postal /usr/bin/postal
DNS Server configurations
For DNS, you can use DnsMasq if you’re looking for a self-hosted simple DNS solution.
A records
You’ll need these records for accessing the API, management interface & SMTP server.
Hostname | Type | Value |
---|---|---|
postal.example.com | A | 192.168.20.10 |
SPF Record
You can configure a global SPF record for your mail server which means domains don’t need to each individually reference your server IPs. This allows you to make changes in the future.
Hostname | Type | Value |
---|---|---|
spf.postal.example.com | TXT | v=spf1 ip4:192.168.20.10 ~all |
Route domain
If you wish to receive incoming e-mail by forwarding messages directly to routes in Postal, you’ll need to configure a domain for this just to point to your server using an MX record.
Hostname | Type | Value |
---|---|---|
routes.postal.example.com | MX | 10 postal.example.com |
Return Path
The return path domain is the default domain that is used as the MAIL FROM
for all messages sent through a mail server. You should add DNS records as below.
Hostname | Type | Value |
---|---|---|
rp.postal.example.com | A | 192.168.20.10 |
rp.postal.example.com | TXT | v=spf1 a mx include:spf.postal.example.com ~all |
Example of Cloudflare DNS Configurations:
postal.example.com points to 192.168.20.10
spf.postal.example.com has a record with content v=spf1 ip4:192.168.20.10 ~all
postal.example.com handles mail for routes.postal.example.com
rp.postal.example.com points to 192.168.20.10
rp.postal.example.com has a record with content v=spf1 a mx include:spf.postal.example.com ~all.
mx.postal.example.com points to 192.168.20.10
Run the command below and replace postal.example.com
with the actual hostname you want to access your Postal web interface ate
$ sudo postal bootstrap postal.example.com
Latest version is: 2.1.1
=> Creating /opt/postal/config/postal.yml
=> Creating /opt/postal/config/Caddyfile
=> Creating signing private key
This will generate three files in /opt/postal/config
.
postal.yml
is the main postal configuration filesigning.key
is the private key used to sign various things in PostalCaddyfile
is the configuration for the Caddy webserver
Open Postal configuration file.
sudo vim /opt/postal/config/postal.yml
At the minimum, have the following settings:
web:
# The host that the management interface will be available on
host: postal.example.com
# The protocol that requests to the management interface should happen on
protocol: https
main_db:
# Specify the connection details for your MySQL database
host: localhost
username: postal
password: StrongPassword
database: postal
message_db:
# Specify the connection details for your MySQL server that will be house the
# message databases for mail servers.
host: localhost
username: postal
password: StrongPassword
prefix: postal
rabbitmq:
# Specify the connection details for your RabbitMQ server.
host: 127.0.0.1
username: postal
password: StrongPassword
vhost: postal
dns:
# Specifies the DNS record 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.example.com
smtp_server_hostname: postal.example.com
spf_include: spf.postal.example.com
return_path: rp.postal.example.com
route_domain: routes.postal.example.com
track_domain: track.postal.example.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.1
port: 2525
username: # Complete when Postal is running and you can
password: # generate the credentials within the interface.
from_name: Postal
from_address: [email protected]
Edit the file to fit your Postal settings.
When done Initialize database by adding all the appropriate table:
$ sudo postal initialize
[+] Running 5/5
⠿ smtp Pulled 0.5s
⠿ cron Pulled 0.5s
⠿ requeuer Pulled 0.5s
⠿ worker Pulled 0.5s
⠿ web Pulled 0.5s
Initializing database
......
Create your initial admin user
$ sudo postal make-user
Postal User Creator
Enter the information required to create a new Postal user.
This tool is usually only used to create your initial admin user.
E-Mail Address : [email protected]
First Name : Admin
Last Name : User
Initial Password: : ********
User has been created with e-mail address [email protected]
Starting the application
Run the following command to start the Postal application
$ sudo postal start
[+] Running 5/5
⠿ Container postal-cron-1 Started 0.4s
⠿ Container postal-web-1 Started 0.2s
⠿ Container postal-requeuer-1 Started 0.3s
⠿ Container postal-smtp-1 Started 0.3s
⠿ Container postal-worker-1 Started 0.3s
This will run a number of containers on your machine.
You can look at the status at any time using:
$ sudo postal status
NAME COMMAND SERVICE STATUS PORTS
postal-cron-1 "/docker-entrypoint.…" cron running
postal-requeuer-1 "/docker-entrypoint.…" requeuer running
postal-smtp-1 "/docker-entrypoint.…" smtp running
postal-web-1 "/docker-entrypoint.…" web running
postal-worker-1 "/docker-entrypoint.…" worker running
Step 6: Configuring Caddy Web Server
A web proxy is required all web traffic and SSL termination. There are many options for Proxy – Nginx, Apache, HAProxy, e.t.c. In this guide we’re going to use Caddy.
We can run Caddy web server using Docker:
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
Check it’s running:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
67461a34ae39 caddy "caddy run --config …" 20 seconds ago Up 20 seconds postal-caddy
1bc1bac79c15 ghcr.io/postalserver/postal:2.1.1 "/docker-entrypoint.…" About a minute ago Up About a minute postal-smtp-1
c5a04cea4211 ghcr.io/postalserver/postal:2.1.1 "/docker-entrypoint.…" About a minute ago Up About a minute postal-worker-1
e188ee4c2844 ghcr.io/postalserver/postal:2.1.1 "/docker-entrypoint.…" About a minute ago Up About a minute postal-requeuer-1
d7335cd48fa1 ghcr.io/postalserver/postal:2.1.1 "/docker-entrypoint.…" About a minute ago Up About a minute postal-web-1
c4b1cc7a852e ghcr.io/postalserver/postal:2.1.1 "/docker-entrypoint.…" About a minute ago Up About a minute postal-cron-1
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.
Upgrading Postal
Once you have installed Postal, you can upgrade to the latest release it by running this command;
$ sudo postal upgrade
warning: redirecting to https://github.com/postalserver/install/
From https://postalserver.io/start/install
* branch main -> FETCH_HEAD
Already up to date.
No version specified, using latest available version...
Upgrading to 2.1.1
[+] Running 5/5
⠿ worker Pulled 1.5s
⠿ cron Pulled 0.5s
⠿ web Pulled 0.4s
⠿ smtp Pulled 0.5s
⠿ requeuer Pulled 0.5s
Migrating database
[+] Running 5/0
⠿ Container postal-worker-1 Running 0.0s
⠿ Container postal-web-1 Running 0.0s
⠿ Container postal-smtp-1 Running 0.0s
⠿ Container postal-requeuer-1 Running 0.0s
⠿ Container postal-cron-1 Running 0.0s
Step 7: Access Postal Admin Web Dashboard
Access Postal Administration page on https://postal.example.com
You should see Let’s Encrypt SSL certificate in place if your installation was successful. Login with admin user email created earlier.
You’ll get a dashboard which looks like this;
Create your first organization
Provision mail server to start sending and receiving messages using Postal.
Give your mail server a name and choose operation mode.
With the basic configurations required you can now use Postal email delivery software solution.
Refer to the Postal Administration guide for further configurations.