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

Installing Mailtrain on Ubuntu 18.04 the RAM-Friendly Way

Ubuntu 18.04 lamp mariadb

This tutorial will present you learn how to set up Mailtrain on Ubuntu 18.04 the RAM-Friendly means. Mailtrain is an open-source self-hosted publication app, an alternative choice to business e-mail service suppliers like Mailchimp. You should 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 forth).

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 27, 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, via 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.
  • Lets you examine 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.


To run Mailtrain, you want a server with at the 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.

Set up Mailtrain on Ubuntu 18.04 the RAM-Friendly Way

In a earlier tutorial, I defined the way to set up Mailtrain utilizing Docker. Docker is nice for individuals who need to get an software up and operating shortly, nevertheless it’s additionally very useful resource hungry. On a VPS with 1GB RAM that has Mailtrain put in utilizing Docker, the MySQL container typically shuts down as a result of RAM is operating out. So I’m going to point out you a RAM-friendly option to set up Mailtrain on Ubuntu 18.04, which may save about 400MB RAM.

Observe: Mailtrain supplies an set up script, however it might be outdated and you’ll doubtless encounter errors when executing the set up script. This tutorial explains every step to be able to perceive the way it works and get it put in.

Step 1: Set up 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 group 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 following command to put in it on Ubuntu 18.04.

sudo apt set up mariadb-server mariadb-client

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

systemctl standing mariadb

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)
Most important 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 mariadb

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

sudo systemctl allow mariadb

Now run the submit set up safety script.

sudo mysql_secure_installation

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

Ubuntu 18.04 lamp 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. (Notice that the letter Y is capitalized, which suggests it’s the default reply.)

ubuntu 18.04 lamp stack mariadb serverExamine MariaDB server model info.

mariadb –version


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

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 should use username and password of the OS to log into MariaDB console. So you possibly can run the following command to login with out offering MariaDB root password.

sudo mariadb -u root

Create a database for Mailtrain utilizing the following command. I named it mailtrain, however you should 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. Exchange 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: Set up Node.js

Mailtrain is constructed on Node.js, which is a JavaScript run-time surroundings that interprets human-readable JavaScript code into machine code. So we have to set up Node.js on Ubuntu 18.04 as a way 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 verify your Node.js and npm model, run

node -v

npm -v


mailtrain 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 following command. You could enter the password of mtuser.

mariadb -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 possibly can add configurations that override the default configurations in /var/www/mailtrain/config/default.toml file.  We solely want so as to add the following 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 following configurations. This report employee may 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

Change /choose/mailtrain to /var/www/mailtrain. Save and shut this file. Then begin mailtrain.service.

sudo systemctl begin mailtrain.service

Examine its standing. Be certain that it’s operating.

sudo systemctl standing mailtrain.service

Allow auto-start at system boot time.

sudo systemctl allow mailtrain.service

Now that Mailtrain is operating, you’ll be able to entry Mailtrain net interface by way of port 3000.


mailtrain ubuntu 18.04 install

Establishing Reverse Proxy and Enabling HTTPS

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

sudo apt set up nginx

Now you possibly can 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 on/nginx/conf.d/mailtrain-nginx.conf

Discover the following line.


Change the worth of server_name parameter to your personal area identify like  Don’t overlook to create an A document 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

It is best to 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

In the [www] part, add the following two strains to point that mailtrain is behind the Nginx proxy and make it pay attention on native host tackle 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

Set up Let’s Encrypt shopper (certbot) on your Ubuntu 18.04 server.

sudo apt set up software-properties-common

sudo add-apt-repository ppa:certbot/certbot

sudo apt set up certbot python3-certbot-nginx

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

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

docker mailtrain

Now you’ll be able to entry Mailtrain net interface by way of your area identify and a safe HTTPS connection.

Install Mailtrain on Ubuntu 18.04 the RAM-Friendly Way

htop command tells me that my server is utilizing about 500MB RAM. If I run Mailtrain with Docker, it’s about 900MB.

mailtrain system requirements linux

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 handle from http://localhost:3000/ to your sub-domain (

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

In the Mailer Settings, you need to use SMTP when you have your personal e mail server or use Amazon SES.  Truly, you may also use different SMTP relay providers in the SMTP tab. In the screenshot under, I exploit my very own e-mail server. Emails shall be submitted on port 587 with STARTTLS encryption.

mailtrain review

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

Find out how to Deal with Bounce Messages in Mailtrain

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

Should you use a SMTP relay service to ship e mail, they may deal with bounce messages for you. In case you use your personal e mail server to ship e-mail, then it’s essential deal with bounce messages in Mailtrain. Mailtrain presents two methods to deal with bounced messages.

I personally use the VERP technique, as a result of it’s extensively utilized in 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 following textual content.

[verp] enabled=true

In case your Mailtrain server has a SMTP server like Postfix operating, then add the following 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.

mailtrain verp bounce handling

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

Observe that in case you deployed DMARC document on your area identify, then the SPF alignment have to be set to relaxed mode. If it’s set to strict mode, then your publication might fail DMARC verify.

If the Mailtrain bounce dealing with server is listening on port 2525 of and Postfix SMTP server is listening on port 25 of the public IP tackle, then it is advisable 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 following 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 forth/postfix/transport

Edit Postfix primary configuration file.

sudo nano /and so forth/postfix/

Add the following line to the file.

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

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

sudo systemctl restart postfix

Dealing with Bounced Messages by way of Postfix Log

This assumes that Mailtrain is put in on your e-mail server.

Mailtrain is ready to detect bounced messages from Postfix mail log by discovering strains that incorporates standing=bounced. First, it is advisable allow the Postfix log studying server. Edit the manufacturing.toml file.

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

Add the following textual content.

[postfixbounce] enabled=true

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

sudo systemctl restart mailtrain

Now the Postfix log studying server is listening on To let it learn Postfix log, run the following command.

tail -F /var/log/mail.log | nc localhost 5699 –

To make it run in the background, you possibly can create a systemd service unit.

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

Add the following textual content.

[Unit] Description=Postfix bounce notifier

[Service] ExecStart=/bin/sh -c ‘/usr/bin/tail -F /var/log/mail.log | nc localhost 5699 -‘
Restart=all the time

[Install] WantedBy=multi-user.goal

Save and shut the file. Then begin this service and allow auto-start at boot time.

sudo systemctl begin bouncetail

sudo systemctl allow bouncetail

Make sure to restart bouncetail service after you restart mailtrain service. I discovered the bouncetail service causes excessive CPU utilization on my server, so I don’t use this technique.

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

Price this tutorial

[Total: 2 Average: 5]

(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’));