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.

Prerequisites

To run Mailtrain with Docker, you need a server with at least 1GB RAM. This tutorial is done on a $5/month Linode VPS (virtual private server). Once you have a VPS, install Ubuntu on it 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] https://download.docker.com/linux/ubuntu bionic stable

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

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | 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

Output:

 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
     Docs: https://docs.docker.com
 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://github.com/Mailtrain-org/mailtrain.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.

your-server-ip: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;
    server_name newsletter.linuxbabe.com;

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:3000;
        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: newsletter.your-domain.com.

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 newsletter.your-domain.com

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.

open source mailchimp

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]

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.
  • If my answer helped you, please consider supporting this site. Thanks :)