mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
Add a send_email function that takes a template_prefix and context.
This commit replaces all uses of django.core.mail.send_mail with send_email, other than in the password reset flow, since that code looks like it is just a patch to Django's password reset code. The send_email function is in a new file, since putting it in zerver.lib.notifications would create an import loop with confirmation.models. send_future_email will soon be moved into email.py as well.
This commit is contained in:
@@ -2,12 +2,12 @@ from __future__ import absolute_import
|
||||
|
||||
from django.dispatch import receiver
|
||||
from django.contrib.auth.signals import user_logged_in
|
||||
from django.core.mail import send_mail
|
||||
from django.conf import settings
|
||||
from django.template import loader
|
||||
from django.utils.timezone import get_current_timezone_name as timezone_get_current_timezone_name
|
||||
from django.utils.timezone import now as timezone_now
|
||||
from typing import Any, Dict, Optional
|
||||
from zerver.lib.send_email import send_email_to_user
|
||||
from zerver.models import UserProfile
|
||||
|
||||
def get_device_browser(user_agent):
|
||||
@@ -85,10 +85,4 @@ def email_on_new_login(sender, user, request, **kwargs):
|
||||
context['zulip_support'] = settings.ZULIP_ADMINISTRATOR
|
||||
context['user'] = user
|
||||
|
||||
text_content = loader.render_to_string('zerver/emails/notify_new_login.txt', context)
|
||||
html_content = loader.render_to_string('zerver/emails/notify_new_login.html', context)
|
||||
|
||||
sender = settings.NOREPLY_EMAIL_ADDRESS
|
||||
recipients = [user.email]
|
||||
subject = loader.render_to_string('zerver/emails/notify_new_login.subject').strip()
|
||||
send_mail(subject, text_content, sender, recipients, html_message=html_content)
|
||||
send_email_to_user('zerver/emails/notify_new_login', user, context=context)
|
||||
|
||||
Reference in New Issue
Block a user