mailtrain/README.md

250 lines
10 KiB
Markdown
Raw Normal View History

2018-12-25 17:07:51 +00:00
# Mailtrain v2 (beta)
2016-04-04 12:42:36 +00:00
2019-02-17 15:00:00 +00:00
Mailtrain is a self hosted newsletter application built on Node.js (v10+) and MySQL (v8+) or MariaDB (v10+).
2018-12-25 09:02:30 +00:00
![](https://mailtrain.org/mailtrain.png)
2016-04-04 12:42:36 +00:00
## Features
2018-12-25 09:02:30 +00:00
* Subscriber lists management
* List segmentation
* Custom fields
* Email templates (including MJML-based templates)
* Custom reports
* Automation (triggered and RSS campaigns)
* Multiple users with granular user permissions and flexible sharing
* Hierarchical namespaces for enterprise-level situations
2018-12-25 17:07:03 +00:00
* Builtin Zone-MTA (https://github.com/zone-eu/zone-mta) for close-to-zero setup of mail delivery
## Recommended minimal hardware Requirements
* 2 vCPU
* 4096 MB RAM
2016-04-04 13:17:22 +00:00
2017-03-08 16:04:27 +00:00
2018-12-25 09:02:30 +00:00
## Quick Start
### Preparation
Mailtrain creates three URL endpoints, which are referred to as "trusted", "sandbox" and "public". This allows Mailtrain
to guarantee security and avoid XSS attacks in the multi-user settings. The function of these three endpoints is as follows:
- *trusted* - This is the main endpoint for the UI that a logged-in user uses to manage lists, send campaigns, etc.
- *sandbox* - This is an endpoint not directly visible to a user. It is used to host WYSIWYG template editors.
- *public* - This is an endpoint for subscribers. It is used to host subscription management forms, files and archive.
The recommended deployment of Mailtrain would use 3 DNS entries that all points to the **same** IP address. For example as follows:
- *lists.example.com* - public endpoint (A record `lists` under `example.com` domain)
- *mailtrain.example.com* - trusted endpoint (CNAME record `mailtrain` under `example.com` domain that points to `lists`)
- *sbox.mailtrain.example.com* - sandbox endpoint (CNAME record `sbox.mailtrain` under `example.com` domain that points to `lists`)
2018-12-25 11:40:33 +00:00
### Installation on fresh CentOS 7 or Ubuntu 18.04 LTS (public website secured by SSL)
2018-12-25 09:02:30 +00:00
This will setup a publicly accessible Mailtrain instance. All endpoints (trusted, sandbox, public) will provide both HTTP (on port 80)
and HTTPS (on port 443). The HTTP ports just issue HTTP redirect to their HTTPS counterparts.
The script below will also acquire a valid certificate from [Let's Encrypt](https://letsencrypt.org/).
If you are hosting Mailtrain on AWS or some other cloud provider, make sure that **before** running the installation
script you allow inbound connection to ports 80 (HTTP) and 443 (HTTPS).
**Note,** that this will automatically accept the Let's Encrypt's Terms of Service.
Thus, by running this script below, you agree with the Let's Encrypt's Terms of Service (https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf).
1. Login as root. (I had some problems running npm as root on CentOS 7 on AWS. This seems to be fixed by the seemingly extraneous `su` within `sudo`.)
```
sudo su -
```
2018-12-25 17:07:03 +00:00
2. Install GIT
2018-12-25 12:18:28 +00:00
For Centos 7 type:
2018-12-25 09:02:30 +00:00
```
yum install -y git
```
2018-12-25 17:07:03 +00:00
For Ubuntu 18.04 LTS type
2018-12-25 12:18:28 +00:00
```
apt-get install -y git
```
2018-12-25 09:02:30 +00:00
3. Download Mailtrain using git to the `/opt/mailtrain` directory
```
cd /opt
git clone https://github.com/Mailtrain-org/mailtrain.git
cd mailtrain
git checkout development
```
4. Run the installation script. Replace the urls and your email address with the correct values. **NOTE** that running this script you agree
Let's Encrypt's conditions.
2018-12-25 11:40:33 +00:00
For Centos 7 type:
2018-12-25 09:02:30 +00:00
```
2018-12-25 11:55:31 +00:00
bash setup/install-centos7-https.sh mailtrain.example.com sbox.mailtrain.example.com lists.example.com admin@example.com
2018-12-25 09:02:30 +00:00
```
2018-12-25 11:40:33 +00:00
For Ubuntu 18.04 LTS type:
```
2018-12-25 11:55:31 +00:00
bash setup/install-ubuntu1804-https.sh mailtrain.example.com sbox.mailtrain.example.com lists.example.com admin@example.com
2018-12-25 11:40:33 +00:00
```
2018-12-25 09:02:30 +00:00
5. Start Mailtrain and enable to be started by default when your server starts.
```
systemctl start mailtrain
systemctl enable mailtrain
```
6. Open the trusted endpoint (like `https://mailtrain.example.com`)
7. Authenticate as `admin`:`test`
8. Update your password under admin/Account
9. Update your settings under Administration/Global Settings.
10. If you intend to sign your email by DKIM, set the DKIM key and DKIM selector under Administration/Send Configurations.
2018-12-25 11:40:33 +00:00
### Installation on fresh CentOS 7 or Ubuntu 18.04 LTS (local installation)
2018-12-25 09:02:30 +00:00
This will setup a locally accessible Mailtrain instance (primarily for development and testing).
All endpoints (trusted, sandbox, public) will provide only HTTP as follows:
- http://localhost:3000 - trusted endpoint
- http://localhost:3003 - sandbox endpoint
- http://localhost:3004 - public endpoint
2018-12-25 09:11:47 +00:00
1. Login as root. (I had some problems running npm as root on CentOS 7 on AWS. This seems to be fixed by the seemingly extraneous `su` within `sudo`.)
2018-12-25 09:02:30 +00:00
```
2018-12-25 09:11:47 +00:00
sudo su -
2018-12-25 09:02:30 +00:00
```
2. Install git
2018-12-25 12:18:28 +00:00
For Centos 7 type:
2018-12-25 09:02:30 +00:00
```
yum install -y git
```
2018-12-25 12:18:28 +00:00
For Ubuntu 18.04 LTS type:
```
apt-get install -y git
```
2018-12-25 09:02:30 +00:00
3. Download Mailtrain using git to the `/opt/mailtrain` directory
```
cd /opt
git clone https://github.com/Mailtrain-org/mailtrain.git
cd mailtrain
git checkout development
```
4. Run the installation script. Replace the urls and your email address with the correct values. **NOTE** that running this script you agree
Let's Encrypt's conditions.
2018-12-25 11:40:33 +00:00
For Centos 7 type:
2018-12-25 09:02:30 +00:00
```
2018-12-25 11:55:31 +00:00
bash setup/install-centos7-local.sh
2018-12-25 09:02:30 +00:00
```
2018-12-25 11:40:33 +00:00
For Ubuntu 18.04 LTS type:
```
2018-12-25 11:55:31 +00:00
bash setup/install-ubuntu1804-local.sh
2018-12-25 11:40:33 +00:00
```
2018-12-25 09:02:30 +00:00
5. Start Mailtrain and enable to be started by default when your server starts.
```
systemctl start mailtrain
systemctl enable mailtrain
```
6. Open the trusted endpoint http://localhost:3000
7. Authenticate as `admin`:`test`
2018-12-25 17:07:03 +00:00
### Deployment with Docker and Docker compose
This setup starts a stack composed of Mailtrain, MongoDB, Redis, and MariaDB. It will setup a locally accessible Mailtrain instance with HTTP endpoints as follows.
- http://localhost:3000 - trusted endpoint
- http://localhost:3003 - sandbox endpoint
- http://localhost:3004 - public endpoint
2019-06-26 16:10:21 +00:00
To make this publicly accessible, you should add reverse proxy that makes these endpoints publicly available over HTTPS. If using the proxy, you also need to set the URL bases and `--withProxy` parameter via `MAILTRAIN_SETTING` as shown below.
An example of such proxy would be:
- http://localhost:3000 -> https://mailtrain.example.com
- http://localhost:3003 -> https://sbox.mailtrain.example.com
2019-07-31 20:26:35 +00:00
- http://localhost:3004 -> https://lists.example.com
2018-12-25 17:07:03 +00:00
2020-01-12 08:31:11 +00:00
To deploy Mailtrain with Docker, you need the following two dependencies installed:
2018-12-25 17:07:03 +00:00
- [Docker](https://www.docker.com/)
- [Docker Compose](https://docs.docker.com/compose/)
These are the steps to start Mailtrain via docker-compose:
1. Download Mailtrain's docker-compose build file
2018-12-25 17:07:03 +00:00
```
2019-02-17 14:50:00 +00:00
curl -O https://raw.githubusercontent.com/Mailtrain-org/mailtrain/development/docker-compose.yml
2018-12-25 17:07:03 +00:00
```
2. Deploy Mailtrain via docker-compose (in the directory to which you downloaded the `docker-compose.yml` file). This will take quite some time when run for the first time. Subsequent executions will be fast.
2018-12-25 17:07:03 +00:00
```
docker-compose up
```
3. Open the trusted endpoint http://localhost:3000
2017-06-24 23:31:57 +00:00
2018-12-25 17:07:03 +00:00
4. Authenticate as `admin`:`test`
2017-06-24 23:31:57 +00:00
The instructions above use an automatically built Docker image on DockerHub (https://hub.docker.com/r/mailtrain/mailtrain). If you want to build the Docker image yourself (e.g. when doing development), use the `docker-compose-local.yml` located in the project's root directory.
### Docker Environment Variables
2020-01-12 08:31:11 +00:00
When using Docker, you can override the default Mailtrain settings via the following environment variables. These variables have to be defined in the docker-compose config
file. You can give them a value directly in the `docker-compose.yml` config file.
Alternatively, you can just declare them there leaving their value empty
(see https://docs.docker.com/compose/environment-variables/#pass-environment-variables-to-containers). In that case, the
value can be provided via a file called `.env` or via environment
variables (e.g. `URL_BASE_TRUSTED=https://mailtrain.domain.com (and more env-vars..) docker-compose -f docker-compose.yml build (or up)`)
| Parameter | Description |
| --------- | ----------- |
| URL_BASE_TRUSTED | sets the trusted url of the instance (default: http://localhost:3000) |
| URL_BASE_SANDBOX | sets the sandbox url of the instance (default: http://localhost:3003) |
2019-12-06 13:43:48 +00:00
| URL_BASE_PUBLIC | sets the public url of the instance (default: http://localhost:3004) |
2020-01-06 09:28:07 +00:00
| WWW_PROXY | use if Mailtrain is behind an http reverse proxy (default: false) |
| MONGO_HOST | sets mongo host (default: mongo) |
| REDIS_HOST | sets redis host (default: redis) |
| MYSQL_HOST | sets mysql host (default: mysql) |
2019-12-06 13:43:48 +00:00
| MYSQL_DATABASE | sets mysql database (default: mailtrain) |
| MYSQL_USER | sets mysql user (default: mailtrain) |
2019-12-06 13:43:48 +00:00
| MYSQL_PASSWORD | sets mysql password (default: mailtrain) |
| WITH_LDAP | use if you want to enable LDAP authentication |
| LDAP_HOST | LDAP Host for authentication (default: ldap) |
| LDAP_PORT | LDAP port (default: 389) |
| LDAP_SECURE | use if you want to use LDAP with ldaps protocol |
| LDAP_BIND_USER | User for LDAP connexion |
| LDAP_BIND_PASS | Password for LDAP connexion |
| LDAP_FILTER | LDAP filter |
| LDAP_BASEDN | LDAP base DN |
| LDAP_UIDTAG | LDAP UID tag (e.g. uid/cn/username) |
| POOL_NAME | sets builtin Zone-MTA pool name (default: os.hostname()) |
2017-03-04 16:20:32 +00:00
2020-01-12 08:31:11 +00:00
If you don't want to modify the original `docker-compose.yml`, you can put your overrides to another file (e.g. `docker-compose.override.yml`) -- like the one below.
```
version: '3'
services:
mailtrain:
environment:
- URL_BASE_TRUSTED
- URL_BASE_SANDBOX
- URL_BASE_PUBLIC
```
2016-04-04 12:36:30 +00:00
## License
**GPL-V3.0**