Ticket #31448: patch.diff

File patch.diff, 2.8 KB (added by Pepe Bawagan, 5 years ago)
  • django/core/mail/__init__.py

    diff --git a/django/core/mail/__init__.py b/django/core/mail/__init__.py
    index d17058b0d4..96840e24db 100644
    a b def send_mail(subject, message, from_email, recipient_list,  
    6363def send_mass_mail(datatuple, fail_silently=False, auth_user=None,
    6464                   auth_password=None, connection=None):
    6565    """
    66     Given a datatuple of (subject, message, from_email, recipient_list), send
    67     each message to each recipient list. Return the number of emails sent.
     66    Given a datatuple of (subject, message, from_email, recipient_list, opts),
     67    send each message to each recipient list. Return the number of emails sent.
    6868
    6969    If from_email is None, use the DEFAULT_FROM_EMAIL setting.
    7070    If auth_user and auth_password are set, use them to log in.
    7171    If auth_user is None, use the EMAIL_HOST_USER setting.
    7272    If auth_password is None, use the EMAIL_HOST_PASSWORD setting.
    7373
     74    opts is a dictionary of the following optional arguments:
     75        - html_message
     76
    7477    Note: The API for this method is frozen. New code wanting to extend the
    7578    functionality should use the EmailMessage class directly.
    7679    """
    def send_mass_mail(datatuple, fail_silently=False, auth_user=None,  
    7982        password=auth_password,
    8083        fail_silently=fail_silently,
    8184    )
    82     messages = [
    83         EmailMessage(subject, message, sender, recipient, connection=connection)
    84         for subject, message, sender, recipient in datatuple
    85     ]
     85
     86    messages = []
     87    for subject, message, sender, recipient, opts in datatuple:
     88        html_message = opts.get('html_message')
     89        message = EmailMessage(
     90            subject, message, sender, recipient,
     91            connection=connection,
     92            html_message=html_message
     93        )
     94        messages.append(message)
     95
    8696    return connection.send_messages(messages)
    8797
    8898
  • django/core/mail/message.py

    diff --git a/django/core/mail/message.py b/django/core/mail/message.py
    index e2bd712f56..b66f33549c 100644
    a b class EmailMessage:  
    185185
    186186    def __init__(self, subject='', body='', from_email=None, to=None, bcc=None,
    187187                 connection=None, attachments=None, headers=None, cc=None,
    188                  reply_to=None):
     188                 reply_to=None, html_message=None):
    189189        """
    190190        Initialize a single email message (which can be sent to multiple
    191191        recipients).
    class EmailMessage:  
    227227        self.extra_headers = headers or {}
    228228        self.connection = connection
    229229
     230        if html_message:
     231            self.attach_alternative(html_message, 'text/html')
     232
    230233    def get_connection(self, fail_silently=False):
    231234        from django.core.mail import get_connection
    232235        if not self.connection:
Back to Top