mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	deliver_email.py: Migrate to send_mail from EmailMultiAlternatives.
This commit is contained in:
		@@ -12,7 +12,7 @@ from __future__ import absolute_import
 | 
			
		||||
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.core.management.base import BaseCommand
 | 
			
		||||
from django.core.mail import EmailMultiAlternatives, get_connection
 | 
			
		||||
from django.core.mail import get_connection, send_mail
 | 
			
		||||
from django.utils.html import format_html
 | 
			
		||||
 | 
			
		||||
from zerver.models import ScheduledJob
 | 
			
		||||
@@ -54,15 +54,15 @@ def get_sender_as_string(dictionary):
 | 
			
		||||
def send_email_job(job):
 | 
			
		||||
    # type: (ScheduledJob) -> bool
 | 
			
		||||
    data = loads(job.data)
 | 
			
		||||
    fields = {'subject': data["email_subject"],
 | 
			
		||||
              'body': data["email_text"],
 | 
			
		||||
              'from_email': get_sender_as_string(data),
 | 
			
		||||
              'to': [get_recipient_as_string(data)]}
 | 
			
		||||
    subject = data["email_subject"]
 | 
			
		||||
    message = data["email_text"]
 | 
			
		||||
    from_email = get_sender_as_string(data)
 | 
			
		||||
    to_email = get_recipient_as_string(data)
 | 
			
		||||
 | 
			
		||||
    msg = EmailMultiAlternatives(**fields)
 | 
			
		||||
    if data["email_html"]:
 | 
			
		||||
        msg.attach_alternative(data["email_html"], "text/html")
 | 
			
		||||
    return msg.send() > 0
 | 
			
		||||
        html_message = data["email_html"]
 | 
			
		||||
        return send_mail(subject, message, from_email, [to_email], html_message=html_message) > 0
 | 
			
		||||
    return send_mail(subject, message, from_email, [to_email]) > 0
 | 
			
		||||
 | 
			
		||||
class Command(BaseCommand):
 | 
			
		||||
    help = """Deliver emails queued by various parts of Zulip
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user