Postal is a complete and fully featured mail server for use by websites & web servers. Postal can be a better alternative of Sendgrid, Mailchimp, Mailgun and other similar SMTP servers. You can easily host Postal mail server on your system and use this as SMTP server for sending application emails, bulk emails, newsletters etc. This tutorial will help you to install Postal Mail server on Ubuntu. You can also try the same Debian and Linux Mint and share your feedback in comments.
Prerequisites
For installation of Postal mail server on your system, you must have following prerequisites installed on your system. This tutorial will help you to install them.
- Ruby 2.3 or higher
- MySQL or MariaDB database server
- RabbitMQ server
- Node.js (for javascript compilation)
- Git (for accessing the repository)
Step 1 – Install Basic Packages
First, start with the initial package installations on your system. Use below commands to install Git, MariaDB(MySQL) database server and Nginx web server with some other dependencies.
$ sudo apt-get install python-software-properties software-properties-common $ sudo apt-get install git nginx mariadb-server build-essential libmysqlclient-dev
Step 2 – Install Node.js
Now, install the latest Nodejs on your system. Use the following commands to install Nodejs 7 on your system or visit this tutorial to install latest available version.
$ curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - $ sudo apt-get install nodejs
Step 3 – Install Ruby 2.3
After installing Node.js, install Ruby version 2.3 or higher version on your system. First use following commands to add Ruby languege PPA in your system.
$ sudo apt-add-repository ppa:brightbox/ruby-ng -y $ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
Now, use the below commands for installing Ruby 2.3 on system.
$ sudo apt-get update $ sudo apt-get install -y ruby2.3 ruby2.3-dev
Step 4 – Install RabbitMQ Server
You also needs to install RabbitMQ server on your system for messaging. Use following commands enable Erlang packages PPA.
$ wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb $ sudo dpkg -i erlang-solutions_1.0_all.deb
Also enable the RabbitMQ server PPA in your system.
$ echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d/rabbitmq.list $ wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -
Now, you can install RabbitMQ Server package on your system using the following command. This will install all of its dependencies as well.
$ sudo apt-get update $ sudo apt-get install erlang erlang-nox rabbitmq-server
Step 5 – Create Database in MySQL
First, create a database in your MySQL server, Also create a database user for accessing database with the Postal mail server. Also, add a grant that permits Postal to manage all databases that are prefixed with postal-.
$ 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;
Step 6 – Create RabbitMQ VirtualHost
In this step, add a VirtualHost in RabbitMQ server and create a user account to access it with application.
$ rabbitmqctl add_vhost /postal $ rabbitmqctl add_user postal passw0rd $ rabbitmqctl set_permissions -p /postal postal ".*" ".*" ".*"
Step 7 – Install Postal Mail Server
At this point, You have completed all requirements for Postal installation. Let’s start with the user creation for Postal setup. Create a account named postal with following command.
$ sudo useradd -r -m -d /opt/postal -s /bin/bash postal $ sudo setcap 'cap_net_bind_service=+ep' /usr/bin/ruby2.3
Now, clone the postal source code on Github using following command. And add a soft link of the Postal binary file under /usr/bin/ directory to access command globally.
$ sudo -i -u postal git clone https://github.com/atech/postal /opt/postal/app $ ln -s /opt/postal/app/bin/postal /usr/bin/postal
To configure postal, you’ll need to have bundler and procodile installed on your system. Install them both:
$ sudo gem install procodile bundler
Now, switch to postal user and complete all the installations with following commands.
$ su - postal $ postal bundle /opt/postal/app/vendor/bundle $ postal initialize-config $ postal initialize $ postal start
Step 8 – Create Postal Admin User
Now run the postal make-user user to create first Postal administrator account. This account will be used latest to login on Potal dashboard.
$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 : Rahul Last Name : Kumar Initial Password: : ********* User has been created with e-mail address [email protected]
Step 9 – Check Postal Running Status
At this stage, your have a running Postal server. To make sure everything is working properly use the following command. You will find following 5 services there. Make sure all the services are in running stage.
$ postal status
The command output will be as below.
Procodile Version 1.0.16 Application Root /opt/postal/app Supervisor PID 28022 Started 2017-05-16 18:41:53 +0530 || web || Quantity 1 || Command bundle exec puma -C config/puma.rb || Respawning 5 every 3600 seconds || Restart mode usr1 || Log path none specified || Address/Port none || => web.1 Running 18:41 pid:28028 respawns:0 port:- tag:- || worker || Quantity 1 || Command bundle exec rake postal:worker || Respawning 5 every 3600 seconds || Restart mode start-term || Log path none specified || Address/Port none || => worker.1 Running 18:41 pid:28030 respawns:0 port:- tag:- || cron || Quantity 1 || Command bundle exec rake postal:cron || Respawning 5 every 3600 seconds || Restart mode term-start || Log path none specified || Address/Port none || => cron.1 Running 18:41 pid:28032 respawns:0 port:- tag:- || smtp || Quantity 1 || Command bundle exec rake postal:smtp_server || Respawning 5 every 3600 seconds || Restart mode usr1 || Log path none specified || Address/Port none || => smtp.1 Running 18:41 pid:28034 respawns:0 port:- tag:- || requeuer || Quantity 1 || Command bundle exec rake postal:requeuer || Respawning 5 every 3600 seconds || Restart mode term-start || Log path none specified || Address/Port none || => requeuer.1 Running 18:41 pid:28036 respawns:0 port:- tag:-
Step 10 – Setup NGINX for Postal
Postal provides a Nginx configuration file. Just copy this file to your Nginx server. You can simply replace default Nginx configuration file or create a new file.
$ cp /opt/postal/app/resource/nginx.cfg /etc/nginx/sites-available/default
Postal default works with SSL only. So create a self-signed SSL to access Postal dashboard or you can get a free valid certificate from Let’s Encrypt.
$ sudo mkdir /etc/nginx/ssl/ $ sudo cd /etc/nginx/ssl/ $ openssl req -x509 -nodes -newkey rsa:4096 -keyout postal.key -out postal.crt
Finally, reload Nginx web server.
$ sudo service nginx reload
Now access your server with https. You will get Postal dashboard login screen. Enter your administrator account details created in step 8.
Step 11 – Configure Postal Dashboard
At this point, You have a running Postal server. Now you need to configure this to send emails. First, you need to understand the setup. There are three main parts
- Organization => You can create multiple organizations, eg one organization for one client.
- Mail server accounts => Each organization can have multiple mail server account. You can keep them in live or development mode. For eg, an organization can assign one mail server to each production team.
- Domains => Each mail servers can have multiple domains. Remember that Postal will accept emails have from address for domains added here and verified.
Create Organization
So let’s create your first organization after login. Click on Create the first organization button. Enter the name of the organization and short name in the input box.
Build Mail Server
You will be automatically switched to the newly created organization, Now click on build your first mail server button. Input the name of your mail server, short name, and mode of the mail server. There are two type of mode available
- Live => The emails will work properly and reached to destination.
- Development => The emails sent will show in Postal dashboard but they actually not delivered to end users
Add Domains
Now add your first domain from which you need to send emails. This will show you the DNS settings required to update for the added domain. Update all settings in DNS server and complete this step.
Create Credentials
You also need to create credentials for your mail server. There are two types of creadentials.
- SMTP => These credential will required to send emails through SMTP protocol, For example linux mail command, PHPMailer etc.
- API => These are required to send mails through HTTP api.
Step 12 – Testing Postal with Client
Postal provides its client libraries for multiple programming languages. Download the required library from below link and test the setup.
4 Comments
Hi Rahul I just install postal mail server in ubuntu 18.04 when when itry to send message from postal mail I notify software fail or no SMTP server available for gmail.com
Do you have any solution for this
Thanks Ian Innocent! We had exactly the same issue with “postal initialize” and your solution works with the nice guide! Thanks!
I just bought a vps server and domain for moodle to be installed, How much would it cost for you to setup our emails in that server
Hello,
I am grateful for this easy step by step tutorial.
I am using Ubuntu 16.04.3 and I ran into an SQL authentication error when running “postal initialize”.
It kept saying “Password denied for postal@localhost using password YES” and I solved it by manually editing the password in “postal.yaml” file in “/opt/postal/config/”
I hope that this will help someone.