Content email server Linux mailchimp Mailtrain Newsletter App Self Hosted Ubuntu Ubuntu Server

Install Mailtrain Self-Hosted Newsletter App on Ubuntu 16.04 Server

mailtrain mariadb

This tutorial will present you learn how to set up Mailtrain on Ubuntu 16.04 server. Mailtrain is an open-source self-hosted publication app, an alternative choice to business e-mail service suppliers like Mailchimp. You need to use Mailtrain to ship emails to your e mail subscribers by way of your personal e-mail server or through the use of any SMTP relay service (Mailjet, SendGrid, AmazonSES, Mailgun, and so on).

Mailtrain is launched underneath the phrases of GPL license, constructed on Node.js and MySQL/MariaDB. The newest model is v1.24.1, launched on September 28, 2018. Options of Mailtrain are as follows:

  • It permits you to simply handle giant mailing lists (like 1 million subscribers).
  • You’ll be able to add subscribers manually, by way of the API, or import from a CSV file.
  • It helps customized fields (textual content fields, numbers, drop-downs or verify packing containers), merge tags and customized varieties.
  • Listing segmentation.
  • RSS marketing campaign: auto-generate publication from RSS feed and ship it to subscribers.
  • Subscribers can add their GPG public keys and Mailtrain will encrypt the publication for them.
  • Permits you to verify particular person click on statistics for each hyperlink.
  • Superior e-mail template editors and HTML code editor.
  • Automation: ship particular emails when consumer prompts your predefined set off.

Conditions of Putting in Mailtrain on Ubuntu 16.04 Server

To run Mailtrain, you want a server with at the very least 1GB RAM. This tutorial is completed on a $5/month Linode VPS (digital personal server). Upon getting a VPS, set up Ubuntu on it and comply with the directions under. You additionally have to have a website identify. I registered my area identify from NameCheap as a result of the worth is low they usually give whois privateness safety at no cost.

Step 1: Install MariaDB Database Server

Your subscribers knowledge might be saved in a database. Mailtrain helps MySQL and MariaDB. MariaDB is a drop-in alternative for MySQL. It’s developed by former members of MySQL workforce who’re involved that Oracle may flip MySQL right into a closed-source product. So let’s set up the MariaDB database server.

Enter the next command to put in it on Ubuntu 16.04.

sudo apt set up mariadb-server mariadb-client

After it’s put in, MariaDB server ought to be mechanically stared. Use systemctl to examine its standing.

systemctl standing mysql

Pattern output:

● mariadb.service – MariaDB 10.1.34 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Lively: lively (operating) since Sat 2018-09-08 11:13:27 UTC; 21s in the past
Docs: man:mysqld(eight)
Foremost PID: 3473 (mysqld)
Standing: “Taking your SQL requests now…”
Duties: 27 (restrict: 505)
CGroup: /system.slice/mariadb.service
└─3473 /usr/sbin/mysqld

If it’s not operating, begin it with this command:

sudo systemctl begin mysql

To allow MariaDB to routinely begin at system boot time, run

sudo systemctl allow mysql

Now run the publish set up safety script.

sudo mysql_secure_installation

When it asks you to enter MariaDB root password, press Enter key as the basis password isn’t set but. Then enter y to set the basis password for MariaDB server.

mailtrain mariadb

Subsequent, you’ll be able to press Enter to reply all remaining questions, which can take away nameless consumer, disable distant root login and take away check database. This step is a primary requirement for MariaDB database safety. (Word that the letter Y is capitalized, which suggests it’s the default reply.)

mailtrain database setup

Step 2: Create a Database and Consumer for Mailtrain

Now we have to log in to MariaDB console and create a database and consumer for Mailtrain. By default, the MaraiDB package deal on Ubuntu makes use of unix_socket to authenticate consumer login, which principally means you need to use username and password of the OS to log into MariaDB console. So you possibly can run the next command to login with out offering MariaDB root password.

sudo mysql -u root

Create a database for Mailtrain utilizing the next command. I named it mailtrain, however you need to use no matter identify you want. (Don’t miss the semicolon.)

create database mailtrain;

Then enter the command under to create a database consumer for Mailtrain and grant all privileges of the mailtrain database to the consumer. Substitute mtuser and your-password together with your most popular username and password.

grant all privileges on mailtrain.* to [email protected] recognized by ‘mtuser_password’;

Subsequent, create a consumer with learn solely entry to mailtrain database. I named this consumer mt_readonly.

grant choose on mailtrain.* TO [email protected] recognized by ‘mt_readonly_password’;

Flush the privileges desk for the modifications to take impact after which get out of MariaDB console.

flush privileges;


Step three: Install Node.js

Mailtrain is constructed on Node.js, which is a JavaScript run-time setting that interprets human-readable JavaScript code into machine code. So we have to set up Node.js on Ubuntu 16.04 with a purpose to run Mailtrain. Mailtrain requires Node.js 7+. This tutorial will set up the present LTS launch of Node.js (V8.x) from NodeSource repository.

curl -sL | sudo -E bash –
sudo apt set up -y nodejs

The nodejs package deal accommodates the npm (Node.js package deal supervisor) binary, so there’s no want to put in it individually. To examine your Node.js and npm model, run

node -v

npm -v


mailtrain ubuntu 16.04 server nodejs

To compile and set up native addons from npm you additionally want to put in construct instruments:

sudo apt set up -y build-essential

Step four: Run Mailtrain

Go to /var/www/ and fetch Mailtrain information from Github.

cd /var/www/

sudo git clone

Import the preliminary SQL knowledge to the mailtrain database through the use of the next command. It’s essential enter the password of mtuser.

mysql -u mtuser -p mailtrain < /var/www/mailtrain/setup/sql/mailtrain.sql

Create the manufacturing.toml configuration file.

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

On this file, you’ll be able to add configurations that override the default configurations in /var/www/mailtrain/config/default.toml file.  We solely want so as to add the next configurations.

[log] degree=”error”
[www] secret=”Replace this with some random characters”
[mysql] consumer=”mtuser”
[queue] processes=5

Save and shut the file. Then create the mailtrain consumer and group for the mailtrain daemon to run as. Word that we don’t have to create password for this consumer, so we create a system consumer as an alternative of a traditional consumer.

sudo adduser –system –group mailtrain

Create a configuration file for the report employee.

sudo nano /var/www/mailtrain/staff/reviews/config/manufacturing.toml

Add the next configurations. This report employee could have read-only entry to mailtrain database.

[log] degree=”error”
[mysql] consumer=”mt_readonly”

Save and shut the file. Then change the permission of /var/www/mailtrain/.

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

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

And set up required node packages.

cd /var/www/mailtrain

sudo npm set up –no-progress –production –unsafe-perm=true

Copy the systemd service unit file to /and so on/systemd/system/ listing.

sudo cp /var/www/mailtrain/setup/mailtrain.service /and so on/systemd/system/

Open this file.

sudo nano /and so on/systemd/system/mailtrain.service

As a result of we downloaded Mailtrain to /var/www/mailtrain/ listing, so change the working listing from /choose/mailtrain to /var/www/mailtrain. Save and shut this file. Then begin mailtrain.service.

sudo systemctl begin mailtrain.service

Allow auto-start at system boot time.

sudo systemctl allow mailtrain.service

Verify its standing. Make certain it’s operating. If the output says activating (auto-restart), then simply wait a number of moments for Mailtrain to start out.

sudo systemctl standing mailtrain.service

Now that Mailtrain is operating, you possibly can entry Mailtrain net interface by way of port 3000.



Establishing Reverse Proxy and Enabling HTTPS

Earlier than utilizing the Mailtrain net interface, let’s put it behind Nginx after which allow HTTPS. Install Nginx net server on Ubuntu 16.04 with:

sudo apt set up nginx

Now you’ll be able to copy the instance mailtrain-nginx.conf file to /and so forth/nginx/conf.d/ listing.

sudo cp /var/www/mailtrain/setup/mailtrain-nginx.conf /and so on/nginx/conf.d/

Open this file.

sudo nano /and so forth/nginx/conf.d/mailtrain-nginx.conf

Discover the next line.


Change the worth of server_name parameter to your personal area identify like  Don’t overlook to create an A report for this sub-domain.


Save and shut the file. Then check Nginx configurations.

sudo nginx -t

If the check if profitable, reload Nginx for the modifications to take impact.

sudo systemctl reload nginx

You must now have the ability to entry Mailtrain net interface by way of your sub-domain:

Now edit /var/www/mailtrain/config/manufacturing.toml file.

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

Within the [www] part, add the next two strains to point that mailtrain is behind the Nginx proxy and make it pay attention on native host handle solely.


Save and shut the file. Then restart Mailtrain for the change to take impact.

sudo systemctl restart mailtrain

Enabling HTTPS With Let’s Encrypt

Install Let’s Encrypt shopper (certbot) on your Ubuntu 16.04 server.

sudo apt set up software-properties-common

sudo add-apt-repository ppa:certbot/certbot

sudo apt replace

sudo apt set up certbot python3-certbot-nginx

Then you should use the Nginx plugin to routinely get hold of and set up a TLS certificates by executing the next command.

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

mailtrain nginx https

Now you possibly can entry Mailtrain net interface by way of your area identify and a safe HTTPS connection.


Login with username admin and password check. Then change your account e-mail handle and password. Go to settings web page to vary default configurations. It is best to change the service tackle from http://localhost:3000/ to your sub-domain (

Observe: The admin account is a simple goal for hackers. For greatest safety, it’s advisable that you simply change the username from admin to one thing else. The Mailtrain net interface doesn’t present such choice, however you’ll be able to change the username in MariaDB database utilizing SQL command.

Within the Mailer Settings, you need to use SMTP when you have your personal e-mail server or use Amazon SES.  Truly, it’s also possible to use different SMTP relay providers within the SMTP tab. Within the screenshot under, I exploit my very own e mail server. Emails can be submitted on port 587 with STARTTLS encryption.


Save your settings. Then you’ll be able to create an inventory to check the functionalities of Mailtrain.

The right way to Deal with Bounce Messages in Mailtrain

Ultimately, you e mail listing will include addresses you can’t ship emails to. For instance, when a subscriber who makes use of an organization e mail handle leaves the corporate, that e mail tackle shall be deleted. So your e-mail server will obtain bounce message saying that the e-mail can’t be delivered.

In case you use a SMTP relay service to ship e mail, they may deal with bounce messages for you. In the event you use your personal e-mail server to ship e mail, then you should deal with bounce messages in Mailtrain. Mailtrain provides two methods to deal with bounced messages.

I personally use the VERP technique, as a result of it’s extensively used within the e-mail group and in addition as a result of the second technique causes excessive CPU utilization on my server.

VERP Bounce Dealing with

With VERP (variable envelope return path), your e-mail record supervisor makes use of distinctive envelope addresses for every subscriber. To allow VERP, edit the manufacturing.toml file.

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

In case your Mailtrain host has no SMTP server operating, then add the next textual content.

[verp] enabled=true

In case your Mailtrain server has a SMTP server like Postfix operating, then add the next textual content. The bounce dealing with server will pay attention on

[verp] enabled=true

Save and shut the file. Then restart Mailtrain for the modifications to take impact.

sudo systemctl restart mailtrain

In Mailtrain net interface, go to Settings -> VERP Bounce Handlding. Examine Use VERP to catch bounces. Save your settings.


Subsequent, it is advisable create a MX report for the server hostname (, then add A document for this hostname, pointing to your Mailtrain host, so bounce messages may be despatched to your Mailtrain host. Every subscriber in your record may have an distinctive envelope handle like [email protected].

Notice that for those who deployed DMARC report in your area identify, then the SPF alignment have to be set to relaxed mode. If it’s set to strict mode, your publication might fail DMARC examine.

If the Mailtrain bounce dealing with server is listening on port 2525 of and Postfix SMTP server is listening on port 25 of the general public IP handle, then you want to arrange transport map in order that Postfix can relay the bounce message to Mailtrain. Create the transport map file.

sudo nano /and so on/postfix/transport

Add the next line to this file. This tells Postfix to relay emails with tackle like [email protected] to the Mailtrain bounce dealing with server. smtp:[]:2525

Save and shut the file. Then generate the index file.

sudo postmap /and so on/postfix/transport

Edit Postfix essential configuration file.

sudo nano /and so on/postfix/most

Add the next line to the file.

transport_maps = hash:/and so forth/postfix/transport

Save and shut the file. Then restart Postfix for the change to take impact.

sudo systemctl restart postfix

I hope this tutorial helped you put in Mailtrain on Ubuntu 16.04 server. You possibly can go to Mailtrain wiki to seek out extra info on utilizing Mailtrain. As all the time, should you discovered this submit helpful, then subscribe to our free publication to get extra ideas and tips. Take care ?

Fee this tutorial

[Total: 0 Average: 0]

(perform(d, s, id)
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); = id;
js.src = “//”;
fjs.parentNode.insertBefore(js, fjs);
(doc, ‘script’, ‘facebook-jssdk’));