Ad

[Complete Guide] How to install Mailtrain on Ubuntu 18.04 with Docker

Posted docker mailtrain nodejs ubuntu smtp open-source

Introduction

Mailtrain is a very popular open-source, self-hosted, newsletter application which is built on NodeJs and MySQL. Mailtrain allows you to send bulk emails by uploading mailing lists through any of your preferred SMTP service provider.

In this tutorial, you will learn the steps required to successfully install and integrate Mailtrain Open Source Email Newsletter Application on a fresh Linux- Ubuntu 18.04 instance with Docker:

Prerequisites

  1. A hosting server with a minimum of 1GB ram available for Mailtrain service. (To be at safer side, it is recommended to have slightly higher capacity)
  2. Node.js (v7+)
  3. Docker
  4. Docker compose
  5. A user account with Pepipost. If you don't have one, click here to signup and get started with 30,000 emails

Ad Image

Installation

Step 1: Install Node.js (Skip this step, if you already have NodeJs installed)

$ sudo apt install build-essential
$ sudo apt-get install manpages-dev
$ sudo apt-get install nodejs

Step 2: Clone Mailtrain git repository on your server

$ sudo git clone git://github.com/Mailtrain-org/mailtrain.git 
$ cd mailtrain

Step 3: Check docker installation

$ sudo docker -v

You can install docker using the following command (Skip, in case you have docker already installed):

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

Step 4: Check docker-compose installation

$ sudo docker-compose -v

For installation of docker-compose follow these steps (Skip, in case you have docker-compose already installed):

  • Run this command to download the current stable release of Docker Compose:
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  • Apply executable permissions to the binary:
$ sudo chmod +x /usr/local/bin/docker-compose

Step 5: Copy the file docker-compose.override.yml.tmpl to docker-compose.override.yml

$ cp docker-compose.override.yml.tmpl docker-compose.override.yml

Step 6: You can now up the containers

$ sudo docker-compose up -d

Step 7: Now you can check the docker container status by using the following command:

$ sudo docker ps

Image

If you got the above output that means you have successfully installed Mailtrain service on your Linux server.

The next step is to set up a reverse proxy.

Setup reverse proxy

For Apache2:

For Installation of Apache2 server use the commands mentioned below:

$ sudo apt install apache2
$ sudo systemctl start apache2
$ sudo systemctl enable apache2

You can find the Mailtrain server configuration setting for Apache in the following path.

$ vim /var/www/html/mailtrain/setup/mailtrain-apache.conf

Note:- You need to enable Proxy Mod on Apache2 (only if you haven't enabled it yet). This can be done by using the following commands:

$ sudo a2enmod proxy 
$ sudo a2enmod proxy_http

These are the settings you will be adding in your apache2.conf file :

$ vim /etc/apache2/apache2.conf
ProxyPreserveHost On
ProxyPass        "/" "http://127.0.0.1:3000/"
ProxyPassReverse "/" "http://127.0.0.1:3000/"
ServerName example.com
ServerAlias www.example.com

Restart the server

$ sudo service apache2 restart

For Nginx:

For Installation of Nginx server use the commands mentioned below:

$ sudo apt install nginx
$ sudo systemctl start nginx
$ sudo systemctl enable nginx

You can find the Mailtrain server configuration setting for Nginx in the following path.

$ vim /var/www/html/mailtrain/setup/mailtrain-nginx.conf 

These are the settings you will be adding in your nginx.conf file :

$ vim /etc/nginx/nginx.conf
    server {
    listen 80;
    listen [::]:80;

    server_name mailtrain.org www.mailtrain.org;
    access_log /var/log/nginx/mailtrain.log;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://127.0.0.1:3000;
        proxy_redirect off;
    }
}

Restart the server:

$ sudo service nginx restart

With this, you will be able to access Mailtrain dashboard on your domain URL

http://<your-domain-address>

Setup and Integration with SMTP

Now, you will be able to open the dashboard at http://<your-domain-address>, so login with Username: admin and Password: test

Get your Pepipost SMTP credentials

By following the below steps, you will get the Pepipost SMTP credentials:

1. Log in with your user credentials on Pepipost application

2. Open SMTP integration panel using this link

3. You will find your SMTP credentials in SMTP Relay tab

Please check the screenshot provided below for reference:

Updating Mailtrain settings

1. After successfully logging in click on admin->settings

Image

2. In General Settings section change <Service Address (URL)> from <http://localhost:3000/> to <http://[your-domain-address]/> depending on your installation

3. Change <Admin Email> from admin@example.com to your preferred sending from-address

Note:- The from-address domain name should be the registered and verified domain that you have integrated with your Pepipost account.

4. Find SMTP tab inside < Mailer Settings > section

5. Change Hostname to [smtp.pepipost.com]

6. Change Port to [25] (If you are using a hosting server that blocks port 25 you can also use port 587)

7. Change Encryption to [Use STARTTLS — usually selected for port 587 and 25] option

8. Keep the authentication checkbox disabled

8. Enter your SMTP username and Password

9. Click on [Check Mailer Config] button

Image

10. You Should get an SMTP credential verification popup, which means your SMTP credentials are now ready to be used to send emails.

Image

Creating a new email list

Mailtrain allows you to create an email list that can be used to send emails to a bunch of email addresses at once. This list you can use to send newsletters too.

Here are the steps to create a new email list:

1. Click on the Lists menu option

2. Enter Name, Description and click on create a list

3. In the Lists menu, you would be able to see a newly created list

Image

Uploading email ids to the email list

Mailtrain gives two options to upload emails to the list:

1. Adding subscribers through CSV upload

a. In Lists-> [your-list-name] click on [List Actions]->[Import Subscribers]

Image

b. Browse for the CSV file containing the list of Email addresses.

c. You can set [Categorize the imported subscribers as], as per your requirement. For importing the email list to our subscriber's list you need to keep the subscriber radio box selected.

d. [Check imported emails:] option checks if your imported email is valid else it will reject the emails that are not. The checks should be implemented if you want to filter emails according to their validity but for a large batch of email lists, it will take more time due to checkups for individual emails.

Image

e. The CSV file that will be imported can have multiple columns namely First name, Lastname, EmailId, Timezone

Image

f. Click on Next button

g. Depending upon the number of Parameters in the CSV files you will get multiple dropdowns to import your uploaded data. Select the fields you want to import and click on the Start Import button.

h. After the import your email list will be populated, if there were any rejected email ids they will be listed with the reason for rejection.

i. You can edit, delete and blacklist the email address in the email list.

Image

2. Adding subscriber through Add subscriber panel

a. In Lists-> [your-list-name] click on [List Actions]->[Add Subscribers]

b. Enter User details

c. Click on Subscribe

Creating Template

Mailtrain has a template creation feature that allows us to create an HTML email template in the mail train panel itself. To create a new email template follow these steps:

1. Click on Templates menu option

2. Enter template name, Select your desired HTML editor (in this tutorial GrapeJS is used), Select HTML Template and description

3. Click on Create Template button

4. With this, your Template will be created and you will be redirected to the edit template screen, now you can edit the newly created email template.

5. Click on open GrapeJS button to edit using GrapeJS UI panel

6. After making necessary changes click on [save] and then close the panel

Image

Create a new campaign

Campaigns in Mailtrain allows us to send relative emails to the targeted audience.

To create a new email campaign please follow these steps:

1. Click on [Campaigns] menu option

2. Go to [Create Campaign] -> [Regular Campaigns]

3. Enter Name of your Campaign and Campaign Description

4. Select the email list which you have created in the previous steps

5. Select an Email template

6. Enter from the address of the campaign with a valid domain name

7. Enter the Subject line for your campaign

8. Click on [Create Campaign]

9. You can edit the template by clicking the Template tab and editing the template either directly or through your template editor.

10. Adding attachments to the email body can easily be done by clicking on [Attachments tab] -> [Add Attachment], Browse the attachment and click on [Upoload] button.

Image

Send Email

1. Go to Campaigns->[Your-campagin]

2. Click on [Send to subscribers] button to send emails to the set email list.

Image

3. After the campaign has been successfully completed, you will be able to see the status of the current campaign emails.

Image

4. You can click on the [Reset] button to reset the status of the current campaign so that you can track your campaign without considering previously ran campaigns. This will reset all of the campaign data regarding earlier campaign runs.

5. Press continue to rerun the campaign without resetting the campaign status.

For Large Import list

1. For the list of 100000 email list, our server took around less than 20 minutes to import emails to our list.

2. You need to disable validation in order to speed up the import process

3. With Mailtrain, it also helps to have change [Max connections] and [Max messages] settings in Advance mailer settings. This will help reduce the time taken to send a large email list.

Updating Advanced Mailer settings

i. Find the [Advanced Mailer settings] section in admin->settings (admin is your username).

ii. There are three options in this section [Max connections],[Max messages] and [Throttling].

iii. [Max connections] is the maximum number of open connections that will be sending emails to your email server. By default these are set to 5, you can change this to greater value for a large email batch.

iv. [Max messages] is the number of emails batches that are sent from each connection to the SMTP server.

v. [Throttling] limits the maximum number of emails you can send in an hour. So in case you enter 5000 then Mailtrain will send not more than 5000 emails per hour.

Image

4. With [Max connections] set to 50, [Max messages] set to 1000 you'll able to achieve to send 100000 in just over 50 minutes but results may vary depending on your system and setup.

Conclusion

By following the above steps, you have now successfully installed Mailtrain and are ready to send bulk emails through Pepipost SMTP services. You can easily create HTML email templates using template generator and run Email campaigns on the preferred email lists.