How to Install Mailtrain on Ubuntu 18.04 without Docker
7 min read

How to Install Mailtrain on Ubuntu 18.04 without Docker

In this tutorial, you will install Mailtrain on Ubuntu 18.04. Mailtrain is an alternative to commercial email service providers like Mailchimp which is a newsletter app.
How to Install Mailtrain on Ubuntu 18.04 without Docker


Before we begin talking about how to install Mailtrain on Ubuntu 18.04, let's first understand - What is Mailtrain?

Mailtrain is an alternative to commercial email service providers like Mailchimp which is a newsletter app. It is an open-source and self-hosted application that is used to send emails to your subscribers via any SMTP relay services like Mailjet and AmazonSES or through your own email server.

Now, you are ready to install Maltrain without Docker on Ubuntu 18.04, as represented in this tutorial. Also, we will answer some FAQs to clear your doubts regarding Mailtrain.


  • 1 GB RAM
  • Ubuntu 18.04 server

Step 1 - Install MariaDB Database Server

1) Enter this command to install MariaDB on Ubuntu 18.04‌.

sudo apt install mariadb-server mariadb-client

2) Once installed, MariaDB will start automatically. You can check the status using the following command:

systemctl status mariadb

You will get the following output: ‌


● mariadb.service - MariaDB 10.1.34 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-09-08 11:13:27 UTC; 21s ago
     Docs: man:mysqld(8)
 Main PID: 3473 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 27 (limit: 505)
   CGroup: /system.slice/mariadb.service
           └─3473 /usr/sbin/mysqld

3) If MariaDB is not running, use the following alternative command:‌

sudo systemctl start mariadb

4) To enable MariaDB to start at system boot time, use the following command:‌

sudo systemctl enable mariadb

5)  After that, run a security script:

sudo mysql_secure_installation

6) Press the ENTER key when the MariaDB root password is asked (password is not set at this point in time) and then press y to set the root password.

7) Press the ENTER key to answer all remaining questions. ‌

8) Now, to check the version information of MariaDB server, enter the following command:

mariadb --version

Following should be the output:


mariadb Ver 15.1 Distrib 10.1.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Step 2 - Create a User and Database for Mailtrain

1) Log in to the MariaDB console and create a user. MariaDB package on Ubuntu uses unix_socket to authenticate user login by default, which means the username and password of the OS can be used to log into the console of MariaDB.

After that, you can run the following command to log in without providing the root password of MariaDB:

sudo mariadb -u root

2) Use the following command to create a database. (Don’t miss out on the semicolon):

create database mailtrain;

3) Create a user and grant all the privileges using the following command. Replace pwsuser and pwsuser_password with your preferred username and password.

grant all privileges on mailtrain.* to [email protected] identified by 'pwsuser_password';

4) After that, create a user with read-only access to your mailtrain database.

grant select on mailtrain.* TO [email protected] identified by 'pws_readonly_password';

5) Flush the privileges table for the changes to take effect and sign out of the MariaDB console.

flush privileges;


Step 3 - Install Node.js

1) Now you need to install the current LTS release of Node.js (V8.x) from the NodeSource repository.‌

curl -sL | sudo -E bash -
sudo apt install -y nodejs
Note: The latest release of LTS Node.js is v12 but it doesn’t work with version v1.24.1 of Mailtrain.

2) npm )Node.js package manager) is available in nodejs package. To check your Node.js and npm version, run‌

node -v

npm -v

3) To compile and install native addons from npm, install the build tools:‌

sudo apt install -y build-essential

Step 4 - Run Mailtrain

1) Go to /var/www/ and then fetch Mailtrain files from Github‌.

cd /var/www/

sudo git clone

2) After that, import the SQL data into the database from the following command by entering the password.

mariadb -u pwsuser -p mailtrain < /var/www/mailtrain/setup/sql/mailtrain.sql

3) After that, create a production.toml configuration file‌.

sudo nano /var/www/mailtrain/config/production.toml

4) Add the following configurations, which will override the default configurations. ‌

secret="Replace this with some random characters"

Now, save and close the file.

5) After that, create the mailtrain user and group. There is no requirement to create a password for this user. You can simply create a system user instead of a normal user.

sudo adduser --system --group mailtrain

6) Now, create a configuration file.

sudo nano /var/www/mailtrain/workers/reports/config/production.toml

7) Now, you need to add the following configurations. The report worker will get read-only access to the database.


8) Now, change the permission of ‌/var/www/mailtrain/.

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

sudo chmod o-rwx /var/www/mailtrain/config/

9) After that, install the required node packages.‌

cd /var/www/mailtrain

sudo npm install --no-progress --production --unsafe-perm=true

10) Copy the systemd service unit file to /etc/systemd/system/ directory‌ using the following command.

sudo cp /var/www/mailtrain/setup/mailtrain.service /etc/systemd/system/

11) After that, open this file.

sudo nano /etc/systemd/system/mailtrain.service

Change /opt/mailtrain to /var/www/mailtrain. Comment out the following line.


12)  Save and close this file. Now start mailtrain.service.

sudo systemctl start mailtrain.service

13) Now, check its status with the following command:

sudo systemctl status mailtrain.service

14) After that, you can enable auto-start at system boot time.

sudo systemctl enable mailtrain.service

15) Now the Mailtrain is running and you can access its web interface via port 3000.‌

Mailtrain on Ubuntu

Step 5 - Set up Reverse Proxy and Enable HTTPS

1) Before using the web interface of Mailtrain, firstly you should keep it behind Nginx and enable HTTPS. Install Nginx web server on Ubuntu 18.04.‌

sudo apt install nginx

2) Now, copy the example mailtrain-nginx.conf file to /etc/nginx/conf.d/ directory.

sudo cp /var/www/mailtrain/setup/mailtrain-nginx.conf /etc/nginx/conf.d/

3) Open mailtrain-nginx.conf file.‌

sudo nano /etc/nginx/conf.d/mailtrain-nginx.conf

4) Search the following line.‌


5) After this, change server_name to your own domain name like  Make sure to create an A record for the sub-domain.


6) Save and close the file. Then test if the Nginx configuration is working perfectly.

sudo nginx -t

7) If the test is successful, reload Nginx so that the changes can come into effect.

sudo systemctl reload nginx

Now you will be able to access Mailtrain via:

8) Now edit /var/www/mailtrain/config/production.toml file.

sudo nano /var/www/mailtrain/config/production.toml

9) Now, you have to add the following two lines in the [www] section, to indicate that mailtrain is behind the Nginx and to make it listen to localhost address only.


10) Save and close the file. After that, restart Mailtrain so that the changes can come into effect.

sudo systemctl restart mailtrain

Step 6 - Enable HTTPS With Let’s Encrypt

1) Now you'll install Let’s Encrypt client (certbot) on your Ubuntu 18.04 server‌.

sudo apt install software-properties-common

sudo add-apt-repository ppa:certbot/certbot

sudo apt install certbot python3-certbot-nginx

2) To use the Nginx plugin to install a TLS certificate, run the following command. ‌

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email your-email-address -d

3) Now access your web interface via your domain name and a secure HTTPS connection.‌

4) If you have installed Mailtrain on your email server, use the following SMTP settings. Keep the hostname and Port should be 25.  As you are talking to localhost, there is no need to enable the encryption of authentication.

Save your settings and you can now explore the functionalities of Mailtrain.

FAQs to Install Mailtrain on Ubuntu 18.04

1) How to upload images?

Mailtrain might throw errors when you upload images, so install the imagemagick package to upload images.

sudo apt install imagemagick

2) How to Create Additional Users?

Mailtrain v2 allows the admin to create additional users with granular user permissions and flexible sharing. With version v.1.24.1, you will be able to create users through the database only. Log into MySQL/MariaDB console.

sudo mysql -u root

Use the mailtrain database.

USE mailtrain;

Use the following SQL command to create a user entry.

INSERT INTO `users` (`username`, `password`, `email`, `access_token`, `reset_token`, `reset_expire`, `created`) VALUES ('your-username',PASSWORD("your-password"),'[email protected]',NULL,NULL,NULL,NOW());

To exit the database server type the below command:

All the users have admin privileges in the Mailtrain Web Interface. Also, users created by the above method won't be able to login into the Mainltrain web interface, firstly they need to click on "forgot password" and reset the password.

3) How to Clean Your Email List?

There is a functionality to create segments of people who have not opened your email in the last 60 days and then delete all the email addresses at once.


We hope this simple guide helped you understand how to install Mailtrain on Ubuntu 18.04. To learn more about Mailtrain, visit Mailtrain Wiki.

If you have any queries, please leave a comment below and we’ll be happy to respond to them for sure.