From 6ee845d027932e9f5cce5269e0e65e62a3618d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=B6nig?= Date: Sun, 8 Jan 2017 16:28:33 +0000 Subject: [PATCH] Add html versions of the invite and signup mails This commit adds html versions of the invite and signup mails and renames the existing .txt files to the preferred file extensions '.subject', '.html' and '.txt'. The html versions of the mails are being sent along with the text-only versions by the 'send_confirmation' function. This fixes #3134. --- confirmation/models.py | 20 +++++++---- templates/confirmation/invite_email.html | 36 +++++++++++++++++++ ...email_subject.txt => invite_email.subject} | 0 ...invite_email_body.txt => invite_email.txt} | 0 ...reregistrationuser_confirmation_email.html | 36 +++++++++++++++++++ ...gistrationuser_confirmation_email.subject} | 0 ...reregistrationuser_confirmation_email.txt} | 0 zerver/lib/actions.py | 11 ++++-- 8 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 templates/confirmation/invite_email.html rename templates/confirmation/{invite_email_subject.txt => invite_email.subject} (100%) rename templates/confirmation/{invite_email_body.txt => invite_email.txt} (100%) create mode 100644 templates/confirmation/preregistrationuser_confirmation_email.html rename templates/confirmation/{preregistrationuser_confirmation_email_subject.txt => preregistrationuser_confirmation_email.subject} (100%) rename templates/confirmation/{preregistrationuser_confirmation_email_body.txt => preregistrationuser_confirmation_email.txt} (100%) diff --git a/confirmation/models.py b/confirmation/models.py index bccf7c383c..1a304cae37 100644 --- a/confirmation/models.py +++ b/confirmation/models.py @@ -93,9 +93,9 @@ class ConfirmationManager(models.Manager): return getattr(settings, 'EMAIL_CONFIRMATION_DAYS', 10) def send_confirmation(self, obj, email_address, additional_context=None, - subject_template_path=None, body_template_path=None, + subject_template_path=None, body_template_path=None, html_body_template_path=None, host=None): - # type: (ContentType, Text, Optional[Dict[str, Any]], Optional[str], Optional[str], Optional[str]) -> Confirmation + # type: (ContentType, Text, Optional[Dict[str, Any]], Optional[str], Optional[str], Optional[str], Optional[str]) -> Confirmation confirmation_key = generate_key() current_site = Site.objects.get_current() activate_url = self.get_activation_url(confirmation_key, host=host) @@ -113,8 +113,8 @@ class ConfirmationManager(models.Manager): else: template_name = obj._meta.model_name templates = [ - 'confirmation/%s_confirmation_email_subject.txt' % (template_name,), - 'confirmation/confirmation_email_subject.txt', + 'confirmation/%s_confirmation_email.subject' % (template_name,), + 'confirmation/confirmation_email.subject', ] if subject_template_path: template = loader.get_template(subject_template_path) @@ -122,15 +122,21 @@ class ConfirmationManager(models.Manager): template = loader.select_template(templates) subject = template.render(context).strip().replace(u'\n', u' ') # no newlines, please templates = [ - 'confirmation/%s_confirmation_email_body.txt' % (template_name,), - 'confirmation/confirmation_email_body.txt', + 'confirmation/%s_confirmation_email.txt' % (template_name,), + 'confirmation/confirmation_email.txt', ] if body_template_path: template = loader.get_template(body_template_path) else: template = loader.select_template(templates) + if html_body_template_path: + html_template = loader.get_template(html_body_template_path) + else: + html_template = loader.get_template('confirmation/%s_confirmation_email.html' % (template_name,)) body = template.render(context) - send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [email_address]) + if html_template: + html_content = html_template.render(context) + send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [email_address], html_message=html_content) return self.create(content_object=obj, date_sent=now(), confirmation_key=confirmation_key) diff --git a/templates/confirmation/invite_email.html b/templates/confirmation/invite_email.html new file mode 100644 index 0000000000..9ce68025cf --- /dev/null +++ b/templates/confirmation/invite_email.html @@ -0,0 +1,36 @@ + + + + + Zulip + + + + + + +
+

Hi there, +

+

+ {{ referrer.full_name }} ({{ referrer.email }}) wants you to join them on Zulip -- the group communication tool you've always wished you had at work. +

+

+ To get started, visit the link below: +
+ {{ activate_url }} +

+

+ {% if verbose_support_offers %} + Feel free to give us a shout at {{ support_email }}, if you have any questions. + {% else %} + If you are having issues, please contact your Zulip administrator at {{ support_email }}. + {% endif %} +

+

+ Cheers,
+ The Zulip Team +

+
+ + diff --git a/templates/confirmation/invite_email_subject.txt b/templates/confirmation/invite_email.subject similarity index 100% rename from templates/confirmation/invite_email_subject.txt rename to templates/confirmation/invite_email.subject diff --git a/templates/confirmation/invite_email_body.txt b/templates/confirmation/invite_email.txt similarity index 100% rename from templates/confirmation/invite_email_body.txt rename to templates/confirmation/invite_email.txt diff --git a/templates/confirmation/preregistrationuser_confirmation_email.html b/templates/confirmation/preregistrationuser_confirmation_email.html new file mode 100644 index 0000000000..885e201588 --- /dev/null +++ b/templates/confirmation/preregistrationuser_confirmation_email.html @@ -0,0 +1,36 @@ + + + + + Zulip + + + + + + +
+

Hello there. +

+

+ You recently signed up for Zulip. Awesome! +

+

+ To complete signup, visit this link below: +
+ {{ activate_url }} +

+

+ {% if verbose_support_offers %} + Feel free to give us a shout at {{ support_email }}, if you have any questions. + {% else %} + If you are having issues, please contact your Zulip administrator at {{ support_email }}. + {% endif %} +

+

+ Cheers,
+ The Zulip Team +

+
+ + diff --git a/templates/confirmation/preregistrationuser_confirmation_email_subject.txt b/templates/confirmation/preregistrationuser_confirmation_email.subject similarity index 100% rename from templates/confirmation/preregistrationuser_confirmation_email_subject.txt rename to templates/confirmation/preregistrationuser_confirmation_email.subject diff --git a/templates/confirmation/preregistrationuser_confirmation_email_body.txt b/templates/confirmation/preregistrationuser_confirmation_email.txt similarity index 100% rename from templates/confirmation/preregistrationuser_confirmation_email_body.txt rename to templates/confirmation/preregistrationuser_confirmation_email.txt diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 2cad80bd7f..95ee6be054 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -2976,8 +2976,10 @@ def do_send_confirmation_email(invitee, referrer): `invitee` is a PreregistrationUser. `referrer` is a UserProfile. """ - subject_template_path = 'confirmation/invite_email_subject.txt' - body_template_path = 'confirmation/invite_email_body.txt' + subject_template_path = 'confirmation/invite_email.subject' + body_template_path = 'confirmation/invite_email.txt' + html_body_template_path = 'confirmation/invite_email.html' + context = {'referrer': referrer, 'support_email': settings.ZULIP_ADMINISTRATOR, 'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS} @@ -2985,11 +2987,14 @@ def do_send_confirmation_email(invitee, referrer): if referrer.realm.is_zephyr_mirror_realm: subject_template_path = 'confirmation/mituser_invite_email_subject.txt' body_template_path = 'confirmation/mituser_invite_email_body.txt' + html_body_template_path = None Confirmation.objects.send_confirmation( invitee, invitee.email, additional_context=context, subject_template_path=subject_template_path, - body_template_path=body_template_path, host=referrer.realm.host) + body_template_path=body_template_path, + html_body_template_path=html_body_template_path, + host=referrer.realm.host) @statsd_increment("push_notifications") def handle_push_notification(user_profile_id, missed_message):