How to Install Mailtrain on Ubuntu 18.04 with Docker

This tutorial will show you how to install Mailtrain on Ubuntu 18.04. Mailtrain is an open-source self-hosted newsletter app, an alternative to commercial email service providers like Mailchimp. You can use Mailtrain to send emails to your email subscribers via your own email server or by using any email-sending service (Mailjet, SendGrid, AmazonSES, Mailgun, etc) via SMTP relay.

Mailtrain is released under the terms of GPL v3.0 license, built on Node.js and MySQL/MariaDB. The latest version is v1.24.1, released on September 27, 2018. Features of Mailtrain are as follows:

  • It allows you to easily manage large mailing lists (like 1 million subscribers).
  • You can add subscribers manually, through the API, or import from a CSV file.
  • It supports custom fields (text fields, numbers, drop-downs or checkboxes), merge tags and custom forms.
  • List segmenation.
  • RSS campaign: auto-generate newsletter from RSS feed and send it to subscribers.
  • Subscribers can upload their GPG public key and Mailtrain will encrypted newsletters.
  • Allows you to check individual click statistics for every link.
  • Advanced template editors and HTML code editor.
  • Automation: send specific emails when user activates your predefined trigger.


To run Mailtrain with Docker, you need a server with at least 1GB RAM. You can click this special link to get $100 free credit on DigitalOcean. (For new users only). If you are already a DigitalOcean user, then you can click this special link to get $50 free credit on Vultr (for new users only). Once you have an account at DigitalOcean or Vultr, install Ubuntu 18.04 on your server and follow the instructions below.

You also need to have a domain name. I registered my domain name from NameCheap because the price is low and they give whois privacy protection for free.

How to Install Mailtrain on Ubuntu 18.04 Server

The most easy way to install Mailtrain is by using Docker. First we need to install Docker and Docker Compose, the latest version of which can be installed from Docker’s official repository. The following steps are for Ubuntu 18.04.

Create a source list file for Docker repository.

sudo nano /etc/apt/sources.list.d/docker.list

Copy the following line and paste it into the file.

deb [arch=amd64] bionic stable

Save and  close the file. Then import Docker’s PGP key by running the command below.

curl -fsSL | sudo apt-key add -

Since this repository uses HTTPS connection, we also need to install apt-transport-https and  ca-certificates package.

sudo apt install apt-transport-https ca-certificates

Next, update package index and install the latest version of Docker CE (Community Edition).

sudo apt update

sudo apt install docker-ce

Once installed, the Docker daemon should be automatically started. You can check it with:

systemctl status docker


 docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2018-10-17 16:27:42 CST; 9min ago
 Main PID: 6675 (dockerd)
    Tasks: 18
   CGroup: /system.slice/docker.service
           ├─6675 /usr/bin/dockerd -H fd://
           └─6696 docker-containerd --config /var/run/docker/containerd/containerd.toml

If it’s not running, then start the daemon with this command:

sudo systemctl start docker

And enable auto-start on system boot:

sudo systemctl enable docker

Check Docker version.

docker -v

Sample output:

Docker version 18.06.1-ce, build e68fc7a

You can install the latest version of docker compose using the pip Python package manager.

sudo apt install python-pip

sudo pip install docker-compose

Check Docker Compose version.

docker-compose --version

Sample output:

docker-compose version 1.22.0, build f46880f

Running Mailtrain with Docker

Download Mailtrain files from the Github repository.

sudo apt install git

git clone git://

Change the name of a file.

cd mailtrain

mv docker-compose.override.yml.tmpl docker-compose.override.yml

Now you can edit docker-compose.yml file to change the default MySQL user login credentials. Then start containers defined in docker-compose.yml file.

sudo docker-compose up -d

The mailtrain_default network will be created and 3 containers will be running: mailtrain-latest, mysql and redis, as can be seen by issuing the following commands:

sudo docker network ls
sudo docker ps

Now you can access Mailtrain web interface via port 3000.


mailtrain ubuntu

Setting up Reverse Proxy and Enabling HTTPS

Before using the Mailtrain web interface, let’s put it behind Nginx and then enable HTTPS. Install Nginx web server on Ubuntu 18.04 with:

sudo apt install nginx

Create a server block file for Mailtrain.

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

Copy and paste the following lines into the file. You can create a sub-domain for Mailtrain like below. Don’t forget to create an A record for that sub-domain.

server {
    listen [::]:80;
    listen 80;

    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;

Save and close the file. Then test Nginx configurations.

sudo nginx -t

If the test if successful, reload Nginx for the changes to take effect.

sudo systemctl reload nginx

You should now be able to access Mailtrain web interface via your sub-domain:

Enabling HTTPS With Let’s Encrypt

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

Then you can use the Nginx plugin to automatically obtain and install a TLS certificate by executing the following command.

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

docker mailtrain

Now you can access Mailtrain web interface via your domain name and a secure HTTPS connection.

install mailtrain on ubuntu 18.04

Login with username admin and password test. Then change your account email address and password. Go to settings page to change default configurations. You should change the service address from http://localhost:3000/ to your sub-domain.

In the Mailer Settings, you can use SMTP if you have your own email server or use Amazon SES.  Actually, you can also use other SMTP relay services in the SMTP tab.

mailtrain smtp settings

Save your settings. Then you can create a list to test the functionalities of Mailtrain.

I hope this tutorial helped you install Mailtrain on Ubuntu 18.04 with Docker. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care.

Rate this tutorial
[Total: 2 Average: 4.5]

2 Responses to “How to Install Mailtrain on Ubuntu 18.04 with Docker

  • Hi Xiao

    I was just wondering would it be possible for you to do a complete docker tutorial?

    Tutorial on installing and configuring the following
    Docker Machine
    Docker Compose
    and anything else you think is needed for a complete docker setup

    Your tutorials have helped me a lot. Keep up the good work

    I know this is a big ask to do this tutorial, but I would be really grateful if you could do it.

    Kind Regards,

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community ( for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here