Created
September 8, 2011 15:15
-
-
Save sjl/1203640 to your computer and use it in GitHub Desktop.
Useful Django send_mail wrapper that will automatically add a plain text alternative to outgoing HTML emails.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.core.mail import EmailMultiAlternatives | |
from django.template.defaultfilters import striptags | |
def send_mail(subject, html_message, from_email, recipient_list, fail_silently=False, connection=None): | |
text_message = striptags(html_message) | |
recipient_list = getattr(settings, 'EMAIL_RECIPIENTS_OVERRIDE', recipient_list) | |
msg = EmailMultiAlternatives(subject, text_message, from_email, recipient_list, connection=connection) | |
msg.attach_alternative(html_message, "text/html") | |
msg.send(fail_silently=fail_silently) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment