Vcom Web Tech

A Step-by-Step Postal Email Server on Ubuntu 20.04: A Comprehensive Guide

Introduction:

In the world of email marketing and transactional emails, having a reliable and efficient email server is crucial. Postal is an open-source email server solution that provides a robust platform for sending and tracking emails at scale. In this guide, we’ll walk you through the process of setting up Postal on an Ubuntu 20.04 server.

Prerequisites:

Before getting started, make sure you have the following:

  • A VPS or dedicated server running Ubuntu 20.04.
  • SSH access to the server with sudo privileges.
  • Basic knowledge of Linux command-line interface.

Step 1: Update System Packages:

Begin by updating the package index and upgrading existing packages to their latest versions, using below command:

sudo apt update

sudo apt upgrade

Step 2: Install Dependencies:

Postal requires several dependencies packages which let apt use packages over HTTPS: Install them using:

apt -y install apt-transport-https ca-certificates curl software-properties-common

Step 3: Add the GPG key for Docker Repository:

Then add the GPG key for the official Docker repository to your system, the following commands:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Step 4: Add the Docker repository to APT sources:

add the docker to apt sources , run the following command:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

Step 5: Again Update System Packages:

update the package database with the Docker packages from the newly added repo:

sudo apt update

Step 6: Install Docker:

Finally, install Docker, run below command:

sudo apt install docker-ce

Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running

sudo systemctl status docker

Step 7: Installing Docker Compose and Permissions:

At the time of this writing, the most current stable version is 1.27.4
The following command will download the 1.27.4 release and save the executable file at /usr/local/bin/docker-compose, which will make this software globally accessible as docker-compose, run the following command:

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Next, set the correct permissions so that the docker-compose command is executable:

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

Install basic utility programs required for POSTAL:

apt install git curl jq -y

Step 8: Install postal:

Clone the Postal repository from GitHub, install the required Ruby version, and install Postal:

git clone https://postalserver.io/start/install /opt/postal/install

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

Step 9: Installing MariaDB on Docker:

To install MariaDB, copy and paste the below to your terminal, remember to update the password:

docker run -d \
--name postal-mariadb \
-p 127.0.0.1:3306:3306 \
--restart always \
-e MARIADB_DATABASE=postal \
-e MARIADB_ROOT_PASSWORD=YOUR_DATABASE_PASSWORD \
mariadb

Step 10: Installing RabbitMQ on Docker:

To install RabbitMQ, copy and paste the below to your terminal, remember to update the password.

docker run -d \
--name postal-rabbitmq \
-p 127.0.0.1:5672:5672 \
--restart always \
-e RABBITMQ_DEFAULT_USER=postal \
-e RABBITMQ_DEFAULT_PASS=YOUR_MQ_PASSWORD \
-e RABBITMQ_DEFAULT_VHOST=postal \
rabbitmq:3.8

Step 11: Configure Postal and User create:

Create the Postal configuration file and initialize the database and user create:

postal bootstrap postal.yourdomain.com

nano  /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]

postal initialize

postal make-user

Follow the prompts to configure settings such as database connection and Redis connection.

Step 11: Start Postal:

Start the Postal server and worker processes:

sudo systemctl start postal

Step 12: Installing Caddy on Docker:

To install Caddy, copy and paste the below to your terminal.

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

Step 13: Access Postal:

You can now access Postal via your domain name or server IP address. Open your web browser and navigate to http://your-domain.com or http://your-server-ip.

Conclusion:

Setting up Postal on Ubuntu 20.04 is a straightforward process that can be accomplished in just a few steps. By following this guide, you can have a powerful email server up and running in no time, ready to handle your email delivery needs with ease and efficiency. If you encounter any issues, as on contact [email protected]

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top