(Last Updated On: December 23, 2018)

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 Server on Ubuntu 18.04 LTS. 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.

Install Postal Mail Server on Ubuntu 18.04 LTS

The installation of Postal Mail Server on Ubuntu 18.04 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 18.04 server.

Step 1: Update your system

Like all other installation guides available on Computingforgeeks, we start the installation by ensuring our system is updated.

sudo apt update
sudo apt -y upgrade
sudo apt -y install git 
sudo reboot

Step 2: Install Ruby on Ubuntu 18.04 LTS

Postal Mail Server requires Ruby, install it on your Ubuntu 18.04 using:

sudo apt install software-properties-common
sudo apt-add-repository ppa:brightbox/ruby-ng
sudo apt update
sudo apt install ruby2.3 ruby2.3-dev build-essential

A complete guide for Ruby installation on Ubuntu 18.04 is available on

How to Install Ruby on Ubuntu 18.04 LTS

Step 3: Install MySQL / MariaDB database server

The other requirement of Postal Mail server is a database server.  If you don’t have it installed, use our guides below.

Install MariaDB 10.x on Ubuntu 18.04 and CentOS 7

Also install libmysqlclient-dev

sudo apt -y install libmysqlclient-dev

For MySQL, use:

How to Install MySQL 8.0 on Ubuntu 18.04 / 16.04

After installation of MariaDB/MySQL database server, create a user and database for Seafile.

First login to MySQL shell as root user:

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 48
Server version: 10.3.11-MariaDB-1:10.3.11+maria~bionic-log mariadb.org binary distribution

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;

Confirm access by Logging into the database as postal user:

$ mysql -u postal -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 49
Server version: 10.3.11-MariaDB-1:10.3.11+maria~bionic-log mariadb.org binary distribution

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 RabbitMQ

Postal uses RabbitMQ for queueing. Install RabbitMQ on Ubuntu 18.04 using the link below:

How to install Latest RabbitMQ Server on Ubuntu 18.04 LTS

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 Node.js

Node.js doesn’t come pre-installed on Ubuntu 18.04. You need to install it manually. See the below guide:

Installing Node.js 10 LTS on Ubuntu 18.04 / 16.04 / Debian 9

Step 6: Set Server Requirements

Postal will be executed as its own user on your server. Add a user that will manage Postal Mail server with the home directory of /opt/postal

sudo useradd -r -m -d /opt/postal -s /bin/bash postal

Allow ruby to listen on web ports.

sudo setcap 'cap_net_bind_service=+ep' /usr/bin/ruby2.5

Installing required system-wide gems:

sudo gem install bundler
sudo gem install procodile
sudo gem install nokogiri -v '1.7.2'

Cloning the Postal repository

sudo -i -u postal mkdir -p /opt/postal/app
wget https://postal.atech.media/packages/stable/latest.tgz -O - | sudo -u postal tar zxpv -C /opt/postal/app

Create a symlink for Postal binary.

sudo ln -s /opt/postal/app/bin/postal /usr/bin/postal

Install all the required dependencies required to run the application

postal bundle /opt/postal/vendor/bundle
Generate and Modify Postal Configuration files.

Generate Postal Configuration files using the command:

# postal initialize-config
Created example config file at /opt/postal/config/postal.yml
Created new private key for Let's Encrypt
Created new signing key for DKIM & HTTP requests
Created new private key for default fast server TLS connections
Created new self signed certificate for default fast server TLS connections

Open Postal configuration file.

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.

For DNS, you can use DnsMasq if you’re looking for a self-hosted simple DNS solution.

How to Install and Configure Dnsmasq on Ubuntu 18.04 LTS

When done Initialize database & assets:

postal initialize
Create your initial admin user
# 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

# postal start
Started Procodile supervisor with PID 31196

You can look at the status at any time using:

postal status.

Configuring Nginx

Install nginx

sudo apt -y install nginx

Configure Nginx

sudo cp /opt/postal/app/resource/nginx.cfg /etc/nginx/sites-available/default

If you have Commercial or Let’s Encrypt SSL certificates, place them under:

/etc/nginx/ssl/postal.key --> Private Key
/etc/nginx/ssl/postal.cert --> Certificate

if you don’t have Valid SSL certificates, you can use self-signed SSL certificate:

sudo mkdir /etc/nginx/ssl/
sudo openssl req -x509 -newkey rsa:4096 -keyout /etc/nginx/ssl/postal.key -out /etc/nginx/ssl/postal.cert -days 365 -nodes

Open the file /etc/nginx/sites-available/default and set a proper Domain name for Postal.

server_name postal.example.com;

Restart nginx after making the change:

sudo systemctl restart nginx

Access Postal Administration page on https://postal.example.com

Login with admin user email created earlier.

Configure Postal service to start on boot

We started Postal service by running a command that keeps the service running in the background. If your systems reboot for any reason, the service won’t be started automatically.

You can create a systemd unit file for managing Postal Service:

sudo vim /etc/systemd/system/postal.service

Paste the following into the file:

[Unit]
Description=Postal Mail Platform
After=mysql.service rabbitmq-server.service
Wants=mysql.service rabbitmq-server.service

[Service]
ExecStart=/usr/bin/postal start
ExecStop=/usr/bin/postal stop
ExecReload=/usr/bin/postal restart
User=postal
Restart=on-failure
Type=forking

[Install]
WantedBy=mysql.service rabbitmq-server.service

Reload Systemd

sudo systemctl daemon-reload

Start and enable Postal service

sudo systemctl enable postal
sudo systemctl start postal

You can confirm service status with:

$ sudo systemctl status postal
* postal.service - Postal Mail Platform
   Loaded: loaded (/etc/systemd/system/postal.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-12-22 23:57:00 PST; 8s ago
  Process: 2468 ExecStart=/usr/bin/postal start (code=exited, status=0/SUCCESS)
 Main PID: 2495 (procodile)
    Tasks: 36 (limit: 2319)
   CGroup: /system.slice/postal.service
           |-2495 [procodile] Postal (/opt/postal/app)
           |-2501 [postal] web.1
           |-2503 [postal] worker.1 (i
           |-2509 [postal] cron.1
           |-2511 [postal] smtp.1
           `-2515 [postal] requeuer.1

Dec 22 23:57:00 ubuntu-01 systemd[1]: Starting Postal Mail Platform...
Dec 22 23:57:00 ubuntu-01 postal[2468]: Started Procodile supervisor with PID 2495
Dec 22 23:57:00 ubuntu-01 systemd[1]: Started Postal Mail Platform.

Refer to the Postal Administration guide for further configurations.