2020-04-30 05:46:20 +00:00
|
|
|
from django.core.mail import EmailMultiAlternatives, get_connection
|
|
|
|
|
|
|
|
|
2020-05-19 01:29:14 +00:00
|
|
|
def send_mass_html_mail(email_data, fail_silently=False, auth_user=None,
|
2020-04-30 05:46:20 +00:00
|
|
|
auth_password=None, connection=None):
|
|
|
|
"""
|
|
|
|
Modified version of send_mass_mail to allow html email
|
|
|
|
"""
|
|
|
|
connection = connection or get_connection(
|
|
|
|
username=auth_user,
|
|
|
|
password=auth_password,
|
|
|
|
fail_silently=fail_silently,
|
|
|
|
)
|
|
|
|
|
2020-05-19 01:29:14 +00:00
|
|
|
def _email_from_dict(data):
|
|
|
|
msg = EmailMultiAlternatives(connection=connection, **data)
|
|
|
|
msg.attach_alternative(data['body'], "text/html")
|
2020-04-30 05:46:20 +00:00
|
|
|
return msg
|
|
|
|
|
2020-05-19 01:29:14 +00:00
|
|
|
messages = [_email_from_dict(d) for d in email_data]
|
2020-04-30 05:46:20 +00:00
|
|
|
return connection.send_messages(messages)
|