summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--res/templates/notif.txt12
-rw-r--r--res/templates/notif_mail.txt10
-rw-r--r--res/templates/room.txt6
-rw-r--r--synapse/config/emailconfig.py2
-rw-r--r--synapse/push/mailer.py27
5 files changed, 50 insertions, 7 deletions
diff --git a/res/templates/notif.txt b/res/templates/notif.txt
new file mode 100644
index 0000000000..b515f394c3
--- /dev/null
+++ b/res/templates/notif.txt
@@ -0,0 +1,12 @@
+{% for message in notif.messages %}
+{{ message.sender_name }} ({{ message.ts|format_ts("%H:%M") }})
+{% if message.msgtype == "m.text" %}
+{{ message.body_text_plain }}
+{% elif message.msgtype == "m.image" %}
+{{ message.body_text_plain }}
+{% elif message.msgtype == "m.file" %}
+{{ message.body_text_plain }}
+{% endif %}
+{% endfor %}
+
+View at {{ notif.link }}
diff --git a/res/templates/notif_mail.txt b/res/templates/notif_mail.txt
new file mode 100644
index 0000000000..24843042a5
--- /dev/null
+++ b/res/templates/notif_mail.txt
@@ -0,0 +1,10 @@
+Hi {{ user_display_name }},
+
+{{ summary_text }}
+
+{% for room in rooms %}
+{% include 'room.txt' with context %}
+{% endfor %}
+
+You can disable these notifications at {{ unsubscribe_link }}
+
diff --git a/res/templates/room.txt b/res/templates/room.txt
new file mode 100644
index 0000000000..999d0ae60a
--- /dev/null
+++ b/res/templates/room.txt
@@ -0,0 +1,6 @@
+{{ room.title }}
+You've been invited, join at {{ room.link }}
+
+{% for notif in room.notifs %}
+{% include 'notif.txt' with context %}
+{% endfor %}
diff --git a/synapse/config/emailconfig.py b/synapse/config/emailconfig.py
index 06b076e3f9..b7be67f173 100644
--- a/synapse/config/emailconfig.py
+++ b/synapse/config/emailconfig.py
@@ -38,6 +38,7 @@ class EmailConfig(Config):
                 "notif_from",
                 "template_dir",
                 "notif_template_html",
+                "notif_template_text",
             ]
 
             missing = []
@@ -61,6 +62,7 @@ class EmailConfig(Config):
             self.email_notif_from = email_config["notif_from"]
             self.email_template_dir = email_config["template_dir"]
             self.email_notif_template_html = email_config["notif_template_html"]
+            self.email_notif_template_text = email_config["notif_template_text"]
 
             # make sure it's valid
             parsed = email.utils.parseaddr(self.email_notif_from)
diff --git a/synapse/push/mailer.py b/synapse/push/mailer.py
index c53ae9a547..4fd89b3e90 100644
--- a/synapse/push/mailer.py
+++ b/synapse/push/mailer.py
@@ -19,6 +19,7 @@ from twisted.mail.smtp import sendmail
 import email.utils
 import email.mime.multipart
 from email.mime.text import MIMEText
+from email.mime.multipart import MIMEMultipart
 
 from synapse.util.async import concurrently_execute
 from synapse.util.presentable_names import (
@@ -74,7 +75,12 @@ class Mailer(object):
         env = jinja2.Environment(loader=loader)
         env.filters["format_ts"] = format_ts_filter
         env.filters["mxc_to_http"] = self.mxc_to_http_filter
-        self.notif_template = env.get_template(self.hs.config.email_notif_template_html)
+        self.notif_template_html = env.get_template(
+            self.hs.config.email_notif_template_html
+        )
+        self.notif_template_text = env.get_template(
+            self.hs.config.email_notif_template_text
+        )
 
     @defer.inlineCallbacks
     def send_notification_mail(self, user_id, email_address, push_actions):
@@ -135,16 +141,23 @@ class Mailer(object):
             "rooms": rooms,
         }
 
-        plainText = self.notif_template.render(**template_vars)
+        html_text = self.notif_template_html.render(**template_vars)
+        html_part = MIMEText(html_text, "html", "utf8")
+
+        plain_text = self.notif_template_text.render(**template_vars)
+        text_part = MIMEText(plain_text, "plain", "utf8")
+
+        multipart_msg = MIMEMultipart('alternative')
+        multipart_msg['Subject'] = "New Matrix Notifications"
+        multipart_msg['From'] = self.hs.config.email_notif_from
+        multipart_msg['To'] = email_address
+        multipart_msg.attach(text_part)
+        multipart_msg.attach(html_part)
 
-        text_part = MIMEText(plainText, "html", "utf8")
-        text_part['Subject'] = "New Matrix Notifications"
-        text_part['From'] = self.hs.config.email_notif_from
-        text_part['To'] = email_address
 
         yield sendmail(
             self.hs.config.email_smtp_host,
-            raw_from, raw_to, text_part.as_string(),
+            raw_from, raw_to, multipart_msg.as_string(),
             port=self.hs.config.email_smtp_port
         )