Add email-sending support

This commit is contained in:
Slavi Pantaleev 2018-08-14 14:11:41 +03:00
parent cab54879d1
commit 21da2f572b
11 changed files with 157 additions and 15 deletions

View file

@ -1,3 +1,13 @@
# 2018-08-14
## Email-sending support
The playbook now configures an email-sending service (postfix) by default.
Additional details are available in [Adjusting email-sending settings](docs/configuring-playbook-email.md).
With this, Matrix Synapse is able to send email notifications for missed messages, etc.
# 2018-08-08

View file

@ -0,0 +1,21 @@
# Adjusting email-sending settings (optional)
By default, this playbook sets up a [postfix](http://www.postfix.org/) email server through which all Matrix services send emails.
The email server would attempt to deliver emails directly to their final destination.
This may or may not work, depending on your domain configuration (SPF settings, etc.)
By default, emails are sent from `matrix@<your-domain-name>` (as specified by the `matrix_mailer_sender_address` playbook variable).
Furthmore, if you'd like to relay email through another SMTP server, feel free to redefine a few more playbook variables.
Example:
```yaml
matrix_mailer_sender_address: "another.sender@example.com"
matrix_mailer_relay_use: true
matrix_mailer_relay_host_name: "mail.example.com"
matrix_mailer_relay_host_port: 587
matrix_mailer_relay_auth: true
matrix_mailer_relay_auth_username: "another.sender@example.com"
matrix_mailer_relay_auth_password: "some-password"
```

View file

@ -23,6 +23,8 @@ When you're done with all the configuration you'd like to do, continue with [Ins
## Other configuration options
- [Adjusting email-sending settings](configuring-playbook-email.md) (optional)
- [Storing Matrix media files on Amazon S3](configuring-playbook-s3.md) (optional)
- [Using an external PostgreSQL server](configuring-playbook-external-postgres.md) (optional)

View file

@ -69,6 +69,7 @@ matrix_docker_image_riot: "avhost/docker-matrix-riot:v0.16.0"
matrix_docker_image_s3fs: "xueshanf/s3fs:latest"
matrix_docker_image_goofys: "cloudproto/goofys:latest"
matrix_docker_image_coturn: "instrumentisto/coturn:4.5.0.7"
matrix_docker_image_mailer: "panubo/postfix:latest"
# The Docker network that all services would be put into
matrix_docker_network: "matrix"
@ -89,6 +90,18 @@ matrix_s3_media_store_aws_access_key: "your-aws-access-key"
matrix_s3_media_store_aws_secret_key: "your-aws-secret-key"
matrix_s3_media_store_region: "eu-central-1"
# By default, this playbook sets up a postfix mailer server (running in a container).
# This is so that Matrix Synapse can send email reminders for unread messages.
matrix_mailer_enabled: true
matrix_mailer_sender_address: "matrix@{{ hostname_identity }}"
matrix_mailer_relay_use: false
matrix_mailer_relay_host_name: "mail.example.com"
matrix_mailer_relay_host_port: 587
matrix_mailer_relay_auth: false
matrix_mailer_relay_auth_username: ""
matrix_mailer_relay_auth_password: ""
# By default, this playbook installs the Riot.IM web UI on the `hostname_riot` domain.
# If you wish to connect to your Matrix server by other means,
# you may wish to disable this.

View file

@ -37,6 +37,11 @@
- setup-all
- setup-coturn
- include: tasks/setup_mailer.yml
tags:
- setup-all
- setup-mailer
- include: tasks/setup_synapse.yml
tags:
- setup-all

View file

@ -0,0 +1,56 @@
---
#
# Tasks related to setting up the mailer
#
- name: Ensure mailer environment variables file created
template:
src: "{{ role_path }}/templates/env/{{ item }}.j2"
dest: "{{ matrix_environment_variables_data_path }}/{{ item }}"
mode: 0640
with_items:
- "env-mailer"
- name: Ensure mailer image is pulled
docker_image:
name: "{{ matrix_docker_image_mailer }}"
when: matrix_mailer_enabled
- name: Ensure matrix-mailer.service installed
template:
src: "{{ role_path }}/templates/systemd/matrix-mailer.service.j2"
dest: "/etc/systemd/system/matrix-mailer.service"
mode: 0644
when: matrix_mailer_enabled
#
# Tasks related to getting rid of the mailer (if it was previously enabled)
#
- name: Check existence of matrix-mailer service
stat: path="/etc/systemd/system/matrix-mailer.service"
register: matrix_mailer_service_stat
- name: Ensure matrix-mailer is stopped
service: name=matrix-mailer state=stopped daemon_reload=yes
register: stopping_result
when: "not matrix_mailer_enabled and matrix_mailer_service_stat.stat.exists"
- name: Ensure matrix-mailer.service doesn't exist
file:
path: "/etc/systemd/system/matrix-mailer.service"
state: absent
when: "not matrix_mailer_enabled and matrix_mailer_service_stat.stat.exists"
- name: Ensure Matrix mailer environment variables path doesn't exist
file:
path: "{{ matrix_environment_variables_data_path }}/env-mailer"
state: absent
when: "not matrix_mailer_enabled"
- name: Ensure mailer Docker image doesn't exist
docker_image:
name: "{{ matrix_docker_image_mailer }}"
state: absent
when: "not matrix_mailer_enabled"

View file

@ -11,6 +11,10 @@
- name: Ensure matrix-coturn autoruns and is restarted
service: name=matrix-coturn enabled=yes state=restarted daemon_reload=yes
- name: Ensure matrix-mailer autoruns and is restarted
service: name=matrix-mailer enabled=yes state=restarted daemon_reload=yes
when: matrix_mailer_enabled
- name: Ensure matrix-synapse autoruns and is restarted
service: name=matrix-synapse enabled=yes state=restarted daemon_reload=yes

View file

@ -0,0 +1,8 @@
MAILNAME=matrix-mailer
{% if matrix_mailer_relay_use %}
RELAYHOST={{ matrix_mailer_relay_host_name }}:{{ matrix_mailer_relay_host_port }}
{% endif %}
{% if matrix_mailer_relay_auth %}
RELAYHOST_AUTH=yes
RELAYHOST_PASSWORDMAP={{ matrix_mailer_relay_host_name }}:{{ matrix_mailer_relay_auth_username }}:{{ matrix_mailer_relay_auth_password }}
{% endif %}

View file

@ -86,7 +86,7 @@ web_client: False
# web_client_location: "/path/to/web/root"
# The public-facing base URL for the client API (not including _matrix/...)
# public_baseurl: https://example.com:8448/
public_baseurl: https://{{ hostname_matrix }}/
# Set the soft limit on the number of file descriptors synapse can use
# Zero is used to indicate synapse should set the soft limit to the
@ -563,20 +563,20 @@ password_config:
# If your SMTP server requires authentication, the optional smtp_user &
# smtp_pass variables should be used
#
#email:
# enable_notifs: false
# smtp_host: "localhost"
# smtp_port: 25
# smtp_user: "exampleusername"
# smtp_pass: "examplepassword"
# require_transport_security: False
# notif_from: "Your Friendly %(app)s Home Server <noreply@example.com>"
# app_name: Matrix
# template_dir: res/templates
# notif_template_html: notif_mail.html
# notif_template_text: notif_mail.txt
# notif_for_new_users: True
# riot_base_url: "http://localhost/riot"
{% if matrix_mailer_enabled %}
email:
enable_notifs: true
smtp_host: "matrix-mailer"
smtp_port: 587
require_transport_security: false
notif_from: "Matrix <{{ matrix_mailer_sender_address }}>"
app_name: Matrix
template_dir: /synapse/res/templates
notif_template_html: notif_mail.html
notif_template_text: notif_mail.txt
notif_for_new_users: True
riot_base_url: "https://{{ hostname_riot }}"
{% endif %}
# password_providers:

View file

@ -0,0 +1,20 @@
[Unit]
Description=Matrix mailer
After=docker.service
Requires=docker.service
[Service]
Type=simple
ExecStartPre=-/usr/bin/docker kill matrix-mailer
ExecStartPre=-/usr/bin/docker rm matrix-mailer
ExecStart=/usr/bin/docker run --rm --name matrix-mailer \
--network={{ matrix_docker_network }} \
--env-file={{ matrix_environment_variables_data_path }}/env-mailer \
{{ matrix_docker_image_mailer }}
ExecStop=-/usr/bin/docker kill matrix-mailer
ExecStop=-/usr/bin/docker rm matrix-mailer
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target

View file

@ -10,6 +10,9 @@ After=matrix-postgres.service
After=matrix-goofys.service
Requires=matrix-goofys.service
{% endif %}
{% if matrix_mailer_enabled %}
Wants=matrix-mailer.service
{% endif %}
Wants=matrix-coturn.service
[Service]