Installing Mailtrain on Ubuntu Bionic

Mailtrain Overview

Mailtrain is a self hosted open-source newsletter application built in Node.js and using MariaDB as datastore.


Preparing the Server

1 . Connect yourself to your server via SSH.

2 . Install sudo on the server, if it is not yet installed:

apt install sudo

3 . Create a regular user account with sudo access and switch into it:

adduser my_new_user --gecos "My New User"
usermod -aG sudo my_new_user
su - my_new_user

Reminder: Replace my_new_user with your user name.

4 . Update the already installed software on the system to the latest version:

sudo apt update && sudo apt upgrade -y

5 . Install the required tools:

sudo apt install -y build-essential unzip

6 . Install Node.js and NPM:

curl -sL | sudo -E bash -
sudo apt install -y nodejs

Installing Postfix

To send Mail from your server, a SMTP server is required.

1 . Install Postfix via apt:

sudo apt install -y postfix

2 . When asked choose Internet Site in the list of options:

3 . Enter the mail name for your instance and confirm. The mail name should be a fully qualified domain name (FQDN) resolving to your instances IP address:

Installing MariaDB

1 . Install MariaDB, an open source MySQL fork:

sudo apt install -y mariadb-server

2 . Initialize the MariaDB server:

sudo mysql_secure_installation

3 . Connect to the database server as root user with the password you have set previously:

sudo mysql -u root -p

4 . Create an empty database and remember the credentials for later:

CREATE DATABASE mailtraindb;
GRANT ALL ON mailtraindb.* TO 'mailtrain' IDENTIFIED BY 'password';

Installing Nginx

1 . Install nginx via apt:

sudo apt install -y nginx

2 . Create a configuration file for nginx:

sudo nano /etc/nginx/sites-available/

and put the following content into it:

server {

    listen [::]:80;
    listen 80;


    charset utf-8;
    client_max_body_size 50M;

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_next_upstream error timeout http_502 http_503 http_504;


3 . Activate the configuration by linking the file in the sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

4 . Reload the nginx configuration to enable the new virtual host:

sudo systemctl reload nginx.service

Important: Remember to replace with the domain name you want to use for your Mailtrain installation. Optionally, you can encrypt the HTTP traffic by using a free SSL certificate from Let’s Encrypt.

Installing Mailtrain

1 . Create an empty directory for the Mailtrain application:

sudo mkdir -p /var/www/mailtrain

2 . Change the ownership of the directory to your user:

sudo chown -R my_new_user:my_new_user /var/www/mailtrain

3 . Enter the directory:

cd /var/www/mailtrain

4 . Download and unzip Mailtrain:

mv mailtrain-master/* . && mv mailtrain-master/.* .
rmdir mailtrain-master

5 . Install the required dependencies:

npm install --production

6 . Copy the file config/default.toml as config/production.toml:

cp config/default.toml config/production.toml

7 . Open the newly created file and edit the settings for the MariaDB database, then save it:

nano config/production.toml

8 . Run the server:

NODE_ENV=production npm start

Accessing the Mailtrain Webinterface

1 . Open your web browser and type the domain name of your Mailtrain instance.

2 . Click on Login in the top bar to connect to Mailtrain:

Mailtrain Login

3 . Login with the username admin and password test. Don’t forget to change the password after your first login.

4 . To send mails from Mailtrain, you have to specify the SMTP server configuration like following:

Mailtrain Sender Settings

You have now specify other parameters like your company name, service URL etc. before starting your first e-marketing campaign. For more information how to plan your campaigns, refer to the official documentation.

Discover the Cloud That Makes Sense