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.
This commit is contained in:
Robert Hönig 2017-01-08 16:28:33 +00:00 committed by Tim Abbott
parent 680d30adc2
commit 6ee845d027
8 changed files with 93 additions and 10 deletions

View File

@ -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)

View File

@ -0,0 +1,36 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Zulip</title>
</head>
<body>
<table width="80%" style="align:center; max-width:800px" align="center">
<tr>
<td style="font-size:16px; font-family:Helvetica;">
<p>Hi there,
</p>
<p>
{{ referrer.full_name }} ({{ referrer.email }}) wants you to join them on Zulip -- the group communication tool you've always wished you had at work.
</p>
<p>
To get started, visit the link below:
<br />
<a href="{{ activate_url }}" style="color:#08c">{{ activate_url }}</a>
</p>
<p>
{% if verbose_support_offers %}
Feel free to give us a shout at <a href="mailto:{{ support_email }}" style="color:#08c">{{ support_email }}</a>, if you have any questions.
{% else %}
If you are having issues, please contact your Zulip administrator at <a href="mailto:{{ support_email }}" style="color:#08c">{{ support_email }}</a>.
{% endif %}
</p>
<p>
Cheers,<br />
The Zulip Team
</p>
</td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,36 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Zulip</title>
</head>
<body>
<table width="80%" style="align:center; max-width:800px" align="center">
<tr>
<td style="font-size:16px; font-family:Helvetica;">
<p>Hello there.
</p>
<p>
You recently signed up for Zulip. Awesome!
</p>
<p>
To complete signup, visit this link below:
<br />
<a href="{{ activate_url }}" style="color:#08c">{{ activate_url }}</a>
</p>
<p>
{% if verbose_support_offers %}
Feel free to give us a shout at <a href="mailto:{{ support_email }}" style="color:#08c">{{ support_email }}</a>, if you have any questions.
{% else %}
If you are having issues, please contact your Zulip administrator at <a href="mailto:{{ support_email }}" style="color:#08c">{{ support_email }}</a>.
{% endif %}
</p>
<p>
Cheers,<br />
The Zulip Team
</p>
</td>
</tr>
</table>
</body>
</html>

View File

@ -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):