How to Setup Postal a Mail Server for Incoming & Outgoing Email

Channel: Linux
Abstract: //www.rabbitmq.com/debian/ testing main' Now update your system and then you will be happy to install RabbitMQ on Ubuntu 16.04 using below commands. #

Postal is a complete and fully featured Open source mail delivery server for use by websites & web servers. It was developed by aTech Media to serve their own mail processing requirements but later on, they decided that it should be released as an open source project for the community. It is increasingly common for companies to use their own mail servers and to implement email marketing.

Personally I believe that it's one of the tools that best adapts to carry out these tasks is Sendgrid, but unfortunately, that is private. Just think of Sendgrid, Mailgun or Postmark, but Postal is an excellent alternative and open source mail server with very interesting features and that can be easily installed on our web server. The tool has a nice interface and has been tested for over 6 months, also has a simple API that will allow us to send and receive emails more automatically. A variety of application captures will surely provide a more detailed explanation of the features of this excellent open source messaging server.

Prerequisites

In this article, we will cover the steps to install and setup Postal mail delivery system using Ubuntu 16.04 LTS and its other dependencies. It's recommended for running Postal on an Ubuntu 16.04 server with at least 8GB of memory and enough disk space to store the required repositories. There should be minimum two static IP addresses need to be configured on the system.

  • Ruby 2.3 or higher
  • MySQL or MariaDB database server
  • RabbitMQ server
  • Node.js (for javascript compilation)
  • Git (for accessing the repository)
1) Installing Ruby

Run the command below, after login with 'root' user credentials to install software propertise packages and then add new repository for Ruby and then update your system.

# apt install software-properties-common
# apt-add-repository ppa:brightbox/ruby-ng
# apt update

Once your system is fully updated with latest updates and patches, then we are good to go for installing the required version of Ruby by issuing the below command.

# apt install ruby2.3 ruby2.3-dev build-essential
2) Installing MySQL/MariaDB

To install the required version of MySQL / MariaDB on the base OS of Ubuntu 16.04, use below commands to import its RSA keys and system update.

# apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
# add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirrors.coreix.net/mariadb/repo/10.1/ubuntu xenial main'
# apt update

Now , we can install MariaDB server by using below command.

# apt install mariadb-server libmysqlclient-dev

Press 'Y' to continue the installation of MariaDB server along with its required dependencies. During the installation setup, you will also be required to configure the root password for connecting to its console.

3) Installing RabbitMQ

To install RabbitMQ on Ubuntu 16.04, first, we will download its 'apt-key' and then add this to apt repository using below commands.

# curl -sL https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -
# add-apt-repository 'deb http://www.rabbitmq.com/debian/ testing main'

Now update your system and then you will be happy to install RabbitMQ on Ubuntu 16.04 using below commands.

# apt update
# apt install rabbitmq-server

Press 'Y' to continue installing RabbitMQ on your system.

4) Installing Node.JS

Node.js can be installed by the use of below 'apt' command.

# apt install nodejs
5) Installing Git

Git paclage can be installed by the use of below 'apt' command.

# apt install git

Now we have all the prerequisites installed on our system that tends us to move towards the installation and setup of Postal Email server.

How to install Postal on Ubuntu 16.04

The installation steps are very simple, after completing the prerequisites to run Postal on Ubuntu 16.04. Let's start with the installation steps starting from preparing its database using MySQL.

1) Setup Database for Postal

Connect the MysQL server console using root user credentials to create the corresponding database to prepare it for the smooth operation of Postal email server.

# mysql -u root -p -h 127.0.0.1

After making a connection to the MySQL root console, use below commands to create a new database and a user with a secure password to have some appropriate privileges.

CREATE DATABASE `postal` CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL ON `postal`.* TO `postal`@`127.0.0.1` IDENTIFIED BY "password";

Next, run the following to add a grant that permits a user to manage all databases that are prefixed with postal. This way Postal will handle the creation of databases for your mail servers, after we give it access to do this.

GRANT ALL PRIVILEGES ON `postal-%` . * to `postal`@`127.0.0.1`  IDENTIFIED BY "password";
2) Setup RabbitMQ

Create a RabbitMQ virtual host with the following commands as it requires its own RabbitMQ vhost and user to connect with.

# rabbitmqctl add_vhost /postal
# rabbitmqctl add_user postal password
# rabbitmqctl set_permissions -p /postal postal ".*" ".*" ".*"
3) Preparing your Operating System

Now we will run the following commands to create a new user with a home directory in '/opt/postal' so that postal should be executed as its own user on our server.

# useradd -r -m -d /opt/postal -s /bin/bash postal
4) Installing system-wide gems

Next, we will install the following two dependencies that few projects need.

# gem install bundler
# gem install procodile
5) Clonning Repository

Now, we will clone the source code into the appropriate directory with the following command as your postal user and clone into the /opt/postal/app directory.

# sudo -i -u postal git clone https://github.com/atech/postal /opt/postal/app

We can create a symbolic link to access a postcard from any directory, with the following command.

# ln -s /opt/postal/app/bin/postal /usr/bin/postal
6) Installing Ruby Dependencies

To install the Ruby dependencies that Postcard needs to be able to run, we will use below command that will install all the required dependencies required to run the application using 'postal' user.

# su - postal
# postal bundle /opt/postal/app/vendor/bundle

By default, the configuration is kept outside of the repository file structure and is stored in '/opt/postal/config'. Let's execute the initial configuration of the tool with the following 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

This will create a number of files for your configuration, including various private keys & certificates as well as a default postal.yml configuration file as shown.

Now open the 'postal.yml' file and configure it to match your hostname and database credentials.

vim config/postal.yml

Afterward, we will initialize database & assets by using below command.

postal initialize
7) Creating Initial Admin User

Using below command will guide you through setting up a new admin user for your installation.

$ postal make-user

Next, you'll be prompted for an e-mail address, name & password and then you can then use these when you first login.

How to start Postal application

In order to start postal application, you can simply use below command to run postal in the foreground for testing and development.

postal run

Once everything looks good, you can use below command to run the postal in the background.

postal start

To check the status of its running processes, you can use its status command.

postal status

The Postal management interface and API should sit behind nginx, so you can install it and configure it as appropriate to access the web interface of Postal.

Conclusion

At the end of this article, now you are able to setup Postal mail delivery platform on Ubuntu 16.04. Postal is an ideal tool to replace the services in the cloud that offer the same functionality because it gives us more control and more pleasant management of our information. Postal has its disadvantages and advantages compared to other private or free solutions, so it is convenient to analyze our situation to determine if it is suitable for our use. Similarly, Postal's learning line is quite short, so that in controlled environments, fairly acceptable tests could be given on the use and use of the tool. It is important to emphasize the importance of having a lightweight, secure and open source messaging platform, but more importantly, takes the time to choose between the application that best suits your needs.

Ref From: linoxide
Channels:

Related articles