postal ubuntu

How to Install Postal Mail Server on an Ubuntu 16.04 VPS

We’ll show you, How to Install Postal Mail Server on an Ubuntu 16.04 VPS. Postal is a feature-rich mail server application widely used as an alternative to Sendgrid, Mailchimp, Mailgun and other similar SMPT servers. You can use Postal to send out bulk emails, newsletters etc. This guide should work on other Linux VPS systems as well but it was tested and written for an Ubuntu 16.04 VPS.

Requirements

There are some requirements for this Postal setup.

  • An Ubuntu VPS
  • Ruby version 2.3 or up, MySQL/MariaDB, RabbitMQ, Node.js and Git installed on your server

If you get one of our Managed Linux VPS hosting plans, we’ll install all requirements and set up your server with Postal.

1. Install Basic Packages and Dependencies

First, install some packages and dependencies on your system, including nginx, mariadb, git etc.

[user]$ sudo apt-get install python-software-properties  software-properties-common
[user]$ sudo apt-get install git nginx mariadb-server build-essential libmysqlclient-dev

2. Install Node.js

Next, install the latest version of Node.js on your system. To install the latest (7.x) version, use the following command:

[user]$ curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
[user]$ sudo apt-get install nodejs

3. Install Ruby 2.3

After Nodejs, we need to install Ruby and add the Ruby PPAs:

[user]$ sudo apt-add-repository ppa:brightbox/ruby-ng -y
[user]$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

Next, install Ruby 2.3:

[user]$ sudo apt-get update
[user]$ sudo apt-get install -y ruby2.3 ruby2.3-dev

4. Install RabbitMQ Server

RabbitMQ will be used for messaging, so enable the Erlang PPA with the following command:

[user]$ wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
[user]$ sudo dpkg -i erlang-solutions_1.0_all.deb

You also need to enable the RabbitMQ server PPA:

[user]$ echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d/rabbitmq.list
[user]$ wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -

Next, you can install the RabbitMQ server along with its dependencies:

[user]$ sudo apt-get update
[user]$ sudo apt-get install erlang erlang-nox rabbitmq-server

5. Create Database in MySQL

Create a database and user for your Postal mail server and grant permissions to the user:

[user]$ mysql -u root -p
Enter password:*******
mysql> CREATE DATABASE postal CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;
mysql> GRANT ALL ON `postal`.* TO `postal`@`127.0.0.1` IDENTIFIED BY "passw0rd";
mysql> GRANT ALL ON `postal-%`.* TO `postal`@`127.0.0.1` IDENTIFIED BY "passw0rd";
mysql> FLUSH PRIVILEGES;

Always use a strong password.

6. Create RabbitMQ VirtualHost

Next, create a VirtualHost in your RabbitMQ server and create a new user for your app

[user]$ rabbitmqctl add_vhost /postal
[user]$ rabbitmqctl add_user postal passw0rd
[user]$ rabbitmqctl set_permissions -p /postal postal ".*" ".*" ".*"

7. Install and configure Postal Mail Server

Now that we finished with the prerequesities we can move on to the actual Postal setup. First, we’re gonna start with creating a user(account) named ‘postal’

[user]$ sudo useradd -r -m -d /opt/postal -s /bin/bash postal
[user]$ sudo setcap 'cap_net_bind_service=+ep' /usr/bin/ruby2.3

Next, clone the source code from the Postal GitHub repo and add a soft link to the Postal binary file:

[user]$ sudo -i -u postal git clone https://github.com/atech/postal /opt/postal/app
[user]$ ln -s /opt/postal/app/bin/postal /usr/bin/postal

To configure Postal, you need to install bundler and procodile. Do that with the following command:

[user]$ sudo gem install procodile bundler

To finish with all the installs, switch to the portal user:

[user]$ su - postal
[user]$ postal bundle /opt/postal/app/vendor/bundle
[user]$ postal initialize-config
[user]$ postal initialize

And open your postal.yml file from /opt/postal/config and update it according to your setup.

Run Postal in the background with the following command:

[user]$ postal start

8. Create Postal Admin User

To create the first Postal administrator account, run make-user:

[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 : LinuxHostSupport
Last Name : Admin
Initial Password: : *********

User has been created with e-mail address [email protected]

Again, use a strong password!

9. Check Postal Running Status

Now your Postal is successfully installed, configured and running. Check its status with the following command:

[user]$ postal status

Make sure all services are running and working properly.

10. Configure Nginx with Postal

Postal comes with its own configuration file. You can copy the cfg file to your nginx directory. Replace the default configuration file or create a new one.

[user]$ cp /opt/postal/app/resource/nginx.cfg /etc/nginx/sites-available/default

By default, Postal only works with SSL. You can use a self-signed SSL.

[user]$ sudo mkdir /etc/nginx/ssl/
[user]$ sudo cd /etc/nginx/ssl/
[user]$  openssl req -x509 -nodes -newkey rsa:4096 -keyout postal.key -out postal.crt

Finally, restart nginx for the changes to take effect.

[user]$ sudo service nginx reload

Now you can access the Postal dashboard via https. Use the details from step 8.

That is it. The Postal installation is now complete.

Of course, you don’t have to do any of this if you use one of our Software Installation Services, in which case you can simply ask our expert Linux admins to install Postal for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

 

One thought on “How to Install Postal Mail Server on an Ubuntu 16.04 VPS

Leave a Reply

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