Install and Configure Mailtrain Newsletter App on Ubuntu 16.04 | 18.04 LTS

ubuntu 3344434 640 1

Mailtrain is a self-hosted newsletter application built with Node.js and a database server (MySQL / MariaDB). If you have a large subscriber list and you want an easy way to manage it on a self-hosted platform in your own environment, then Mailtrain should be a good place to start.

This brief tutorial shows students and new users how to install and configure Mailtrain on a self-hosted Ubuntu 16.04 | 18.04 system to easily manage your newsletter subscribers.

Some of the features provided by Mailtrain includes, list management, custom field, encryption, template editor and automation. This app has everything you’d find in a paid list service and it’s free.

For more about Mailtrain, please check its homepage.
To get started with installing Mailtrain on Ubuntu, follow the steps below:

Step 1: Install Node.js

Mailtrain is built on top of Node.js and Node.js is easy to install in Ubuntu.

Before installing the latest version of Node.js, you must add its PPA to Ubuntu. This repository is provided by the official package maintainer. To add the repository, run the commands below.

sudo apt update
sudo apt install curl git

There are two repositories you can install. one repository contains the latest Node.js packages and the other has the LTS or (Long Term Support) packages. if you need the latest and greatest, then install the first repository.

On the other hand, if you need a more stable and tested Node.js packages, then install the LTS repository.

Then for the Latest release, add this PPA.

curl -sL | sudo bash -

To install the LTS release, use this PPA

curl -sL | sudo bash -

After that, you can now install latest version of Node.js from the particular repository you choose. If you add both repositories, the latest version of Node.js will be installed and not the LTS.

To install, run the commands below

sudo apt install nodejs

After installing, both Node.js and NPM modules should be installed and ready to use.

You can use the commands below to view the version number installed.

node -v
npm -v

To test whether the web server is properly installed, run the commands below to create a test file called http_server.js in your home folder.

cd ~/
nano http_server.js

Then copy and paste the content below into the file and save.

const http = require('http');

const hostname = '';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);

After that save the file and run the commands below to start the server.

node http_server.js

You should see an output that reads:

Server running at

Now open your browser and browse to the server hostname or IP address followed by port 3000. and you should see a default page with Hello World

Node.js ubuntu install

Step 2: Install MariaDB

Now that Node.js is installed, continue below to installing MariaDB.

To install MariaDB run the commands below:

sudo apt-get install mariadb-server mariadb-client

After installing MariaDB, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.

Run these on Ubuntu 16.04 LTS

sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl enable mysql.service

Run these on Ubuntu 18.10 and 18.04 LTS

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Next, run the commands below to secure the database server with a root password if you were not prompted to do so during the installation.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

Now that MariaDB is installed, to test whether the database server was successfully installed, run the commands below.

sudo mysql -u root -p

type the root password when prompted.

mariadb welcome

If you see a similar screen as shown above, then the server was successfully installed.

Next, logon to MariaDB database server, run the commands below.

sudo mysql -u root -p

Then create a database called mailtrain


Create a database user called mailtrainuser with a new password

CREATE USER 'mailtrainuser'@'localhost' IDENTIFIED BY 'new_password_here';

Then grant the user full access to the database.

GRANT ALL ON mailtrain.* TO 'mailtrainuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;

Finally, save your changes and exit.


Step 3: Download and Install Mailtrain

At this point, both Node.js and MariaDB should be installed and configured. For this tutorial, I’m going to install Mailtrain in my home directory. Change into the current user home folder and download Mailtrain.

cd ~/
mv mailtrain-master mailtrain

Copy ~/mailtrain/config/default.toml as ~/mailtrain/config/production.toml and update MySQL and any other settings in it.

cp ~/mailtrain/config/default.toml ~/mailtrain/config/production.toml
nano ~/mailtrain/config/production.toml

Then edit the highlighted lines and save the file.

# Some installations, eg. MAMP can use a different port (8889)
# MAMP users should also turn on "Allow network access to MySQL" otherwise MySQL might not be accessible

After that, run the commands below to install all dependencies.

cd ~/mailtrain
npm install --production

After that, run the commands below to start the server

cd ~/mailtrain
NODE_ENV=production npm start

You should see similar lines as below:

> mailtrain@1.24.0 start /home/richrd/mailtrain
> node index.js

info Using local auth 
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
info sql SQL not set up, initializing
info sql Loading tables from mailtrain.sql
info sql Update 25 applied
info sql Update 26 applied
info sql Update 27 applied
info sql Update 28 applied
info sql Update 29 applied
info sql Update 30 applied
info sql Update 31 applied
info sql Update 32 applied
info sql Update 33 applied
info sql Update 34 applied
info sql Database check completed
info Express WWW server listening on port 3000
verb UTC Updating timezone offsets
info Service All services started

Open your browser and browse to the server hostname or IP address followed by port #3000


You should see Mailtrain default homepage.

Ubuntu Mailtrain install

Installation should be complete. Login with the username admin and the password test. Once logged in, update the user information and password via the Mailtrain web interface.

Default username and password:

Username: admin
Password: test

Congratulations! You have successfully install and configured Mailtrain on Ubuntu 16.04 | 18.04.

You may also like the post below:

1 Comment

  1. How can I configure mail settings to my server?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.