You are on page 1of 1

!

Cart Login Free Account

Community Blog Events Webinars Tutorials Forum Search "

Community ! Blog ! How to Setup Postal Mail Server on Ubuntu 18.04

Hiteshjethva
How to Setup Postal Mail Server on Ubuntu 18.04
35 posts | 4 followers
Hiteshjethva March 2, 2020 7,693 " 0
Follow

In this tutorial, we will learn how to install and configure Postal on an Alibaba Cloud Elastic Compute Service (ECS)
Ubuntu 18.04 server.

Related Products

By Hitesh Jethva, Alibaba Cloud Community Blog author.


Web App Service
Introduction Web App Service allows you to deploy, scale, adjust, and
monitor applications in an easy, efficient, secure, and
Postal is a free, open source mail server written in Ruby and JavaScript. It is a feature-rich mail server flexible manner.
application that can be used as an alternative to Sendgrid, Mailchimp, Mailgun and other similar SMTP
servers. Learn More

In this tutorial, we will learn how to install and configure a Postal mail server on an Alibaba Cloud Elastic
Compute Service (ECS) Ubuntu 18.04 server.
Alibaba Mail
Prerequisites Alibaba Mail is one of the only email service providers in
the industry that supports public cloud services and
A fresh Alibaba Cloud instance with Ubuntu 18.04 installed. provides fast, secure, and stable services.
A root password is set up to your instance.
A valid domain name is configured with your instance. Learn More

Create a new ECS instance and connect to your instance as the root user.

Once you are logged into your Ubuntu 18.04 instance, run the following command to update your base Web Hosting
system with the latest available packages.
Explore how our Web Hosting solutions help small and
medium sized companies power their websites and online
apt-get update -y
businesses.

Learn More
Install and ConWgure MariaDB

First, you will need to install MariaDB database server to your server. You can install it with the following
command: Web Hosting Solution

Explore Web Hosting solutions that can power your


apt-get install mariadb-server libmysqlclient-dev -y
personal website or empower your online business.

After installing MariaDB, you will need to secure it first. You can secure it by running the following command: Learn More

mysql_secure_installation

More Posts by Hiteshje… See All !


Answer all the questions as shown below:

Enter current password for root (enter for none): How to Archive VM Backups on Alibaba Cloud with
Set root password? [Y/n]: N Simple 4 Steps?
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y How to Install Zabbix Monitoring Server on Ubuntu
Remove test database and access to it? [Y/n]: Y 20.04
Reload privilege tables now? [Y/n]: Y
Git Branching Naming Convention - Best Practices

Once the MariaDB server is secured, log in to MariaDB shell with the following command: Basics of Working with JSON in SQL Server

5 Reasons Why Cloud Security Is Important For All


mysql -u root -p
Businesses!

Enter your root password, then create a database and user for Postal: Why Is A Database Backup Essential for Enterprises?

7 Tips to Take Your Digital Marketing to The Next Level


MariaDB [(none)]> CREATE DATABASE postal CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;
MariaDB [(none)]> CREATE USER 'postal'@'localhost' IDENTIFIED BY 'password'; 10 Search Engine Optimization Tips to Improve Your
Rankings

Next, grant all the privileges to the postal database:


How to Create an Effective Sales Funnel?

MariaDB [(none)]> GRANT ALL ON postal.* TO 'postal'@'localhost'; What are the main Differences Between Cloud Hosting
MariaDB [(none)]> GRANT ALL PRIVILEGES ON `postal-%`.* to `postal`@`localhost` IDENTIFIED BY "password"; and Shared Hosting?

Next, flush the privileges and exit from the MariaDB shell with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;


MariaDB [(none)]> QUIT;

Install Ruby and RabbitMQ

Next, you will need to install Ruby to your server. By default, Ruby is not available in the Ubuntu 18.04 default
repository. So, you will need to add Ruby repository to your server.

You can add the Ruby repository with the following command:

apt-get install software-properties-common


apt-add-repository ppa:brightbox/ruby-ng

Next, update the repository and install Ruby with the following command:

apt-get update -y
apt-get install ruby2.3 ruby2.3-dev build-essential -y

RabbitMQ is an open source message broker software that implements the Advanced Message Queuing
Protocol. Postal uses RabbitMQ for queueing. So, you will also need to install RabbitMQ and Erlang to your
server.

First, download and add the Erlang GPG key with the following command:

wget -O- https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc | apt-key add -

Next, add the Erlang repository with the following command:

echo "deb https://packages.erlang-solutions.com/ubuntu bionic contrib" | tee /etc/apt/sources.list.d/erlang.list

Next, update the repository and install Erlang with the following command:

apt-get update -y
apt-get install erlang -y

Once Erlang has been installed, you can proceed to install RabbitMQ.

First, download and add the RabbitMQ GPG key with the following command:

wget -O- https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc | apt-key add -


wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | apt-key add -

Next, add the RabbitMQ repository with the following command:

echo "deb https://dl.bintray.com/rabbitmq/debian $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/rabbitmq.list

Next, update the repository and install RabbitMQ with the following command:

apt-get update -y
apt-get install rabbitmq-server -y

Once the RabbitMQ has been installed, check the status of RabbitMQ service with the following command:

systemctl status rabbitmq-server

Next, you will need to create RabbitMQ vhost and user for postal. You can do this with the following
command:

rabbitmqctl add_vhost /postal


rabbitmqctl add_user postal password
rabbitmqctl set_permissions -p /postal postal ".*" ".*" ".*"

Install Nodejs

By default, the latest version of Nodejs is not available in the Ubuntu 18.04 default repository. So, you will
need to add repository for that.

You can add the Nodejs repository with the following command:

curl -sL https://deb.nodesource.com/setup_10.x | bash

Next, update the repository and install Nodejs with the following command:

apt-get install nodejs -y

Install Postal

Before installing Postal, you will need to create a user for postal mail server. You can create it with the
following command:

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

Next, allow ruby to listen on web ports with the following command:

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

Next, install all the required gems with the following command:

gem install bundler

Next, install procodile with gem:

gem install procodile

Next, install nokogiri with gem:

gem install nokogiri -v '1.7.2'

Next, create a directory structure for Postal with the following command:

mkdir -p /opt/postal/app

Next, download the latest version of Postal with the following command:

wget https://postal.atech.media/packages/stable/latest.tgz

Once the download is completed, extract the downloaded file with the following command:

tar zxpv latest.tgz -C /opt/postal/app

Next, change ownership of postal directory with the following command:

chown -R postal:postal /opt/postal

Next, create a symlink for Postal binary with the following command:

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

Next, install all the required dependencies with the following command:

postal bundle /opt/postal/vendor/bundle

Next, generate Postal Configuration files with the following command:

postal initialize-config

Next, open Postal configuration file and make some changes:

nano /opt/postal/config/postal.yml

Make the following changes as per your environment:

web:
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: password
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: password
prefix: postal

rabbitmq:
# Specify the connection details for your RabbitMQ server.
host: 127.0.0.1
username: postal
password: password
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: postal@yourdomain.com

Save and close the file. Then, initialize database with the following command:

postal initialize

Next, you will need to create a admin user for Postal. You can do this with the following command:

postal make-user

Answer all the questions as shown below:

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 : admin@example.com


First Name : Admin
Last Name : Postal
Initial Password: : *********

User has been created with e-mail address admin@example.com

Finally, start the Postal application with the following command:

postal start

You can check the status of Postal with the following command:

postal status

You can stop the Postal service any time with the following command:

postal stop

Create Systemd Service Wle for Postal

Next, you will need to create a systemd service file to manage Postal service. You can do this with the
following command:

nano /etc/systemd/system/postal.service

Add the following lines:

[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

Save and close the file. Then, reload the systemd with the following command:

systemctl daemon-reload

Next, start Postal service and enable it to start on boot with the following command:

systemctl start postal


systemctl enable postal

You can check the status of Postal service with the following command:

systemctl status postal

Install and ConWgure Nginx

Next, you will need to install Nginx to access Postal mail server. First, install Nginx with the following
command:

apt-get install nginx openssl -y

Next, copy Nginx configuration file with the following command:

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

Next, create a self-signed SSL certificate with the following command:

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

Answer all the questions as shown below:

Generating a 4096 bit RSA private key


...............................++
.................++
writing new private key to '/etc/nginx/ssl/postal.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:IN
State or Province Name (full name) [Some-State]:Gujarat
Locality Name (eg, city) []:Ahmedabad
Organization Name (eg, company) [Internet Widgits Pty Ltd]:IT
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:Hitesh
Email Address []:admin@example.com

Next, open the Nginx default virtual host file and define your domain:

nano /etc/nginx/sites-available/default

Make the following changes:

server_name postal.example.com;

Save and close the file. Then, restart Nginx service with the following command:

systemctl restart nginx

Access Postal Web Interface

Now, open your web browser and type the URL https://postal.example.com . You will be redirected to the
following page:

Provide your administrator email and password which you have created earlier. Then, click on the Login
button. You should see the following page:

Next, click on the Create the first organization. You should see the following page:

Next, provide your organization name and click on the Create organization button. You should see the
following page:

That's it! Now, you can easily build your own mail server for your organization.

ECS Tech Share App Dev Tutorials Email Hosting Postal

"0 # 0 $ 0 Share on
% & '
Read previous post: Read next post:
How to Monitor Your Ubuntu 18.04 System with How to Install and Configure Prisma Server on
Sysdig Ubuntu 18.04

You may also like

An Introduction to Logrotate: Manage Log Files on Alibaba How to Set Up Zimbra Collaboration Tool on ECS Ubuntu
Cloud 18.04

Alex - January 22, 2020 Alex - June 21, 2019

How to Install Chkrootkit Security Scanner on Ubuntu How to Install and Configure Prisma Server on Ubuntu
18.04 18.04

Hiteshjethva - January 8, 2020 Hiteshjethva - March 2, 2020

How to Setup Kamailio SIP server on Ubuntu 18.04 How to Setup Shinken Monitoring Tool on ECS Ubuntu
18.04
Hiteshjethva - January 8, 2020
Hiteshjethva - December 12, 2019

Comments

Write your comment...

Post

A Free Trial That Lets You Build Big!


Start building with 50+ products and up to 12 months usage for Elastic Compute Service

Get Started for Free

About Us Privacy Policy Legal Notice List

Alibaba Group Taobao Marketplace Tmall Juhuasuan AliExpress Alibaba.com 1688 Alimama Alitrip YunOS AliTelecom AutoNavi UCWeb Umeng Xiami DingTalk Alipay

© 2009-2022 Copyright by Alibaba Cloud All rights reserved

You might also like