Skip to content

Instantly share code, notes, and snippets.

View Ry4an's full-sized avatar

Ry4an Brase Ry4an

View GitHub Profile
@sjl
sjl / email.py
Created September 8, 2011 15:15
Useful Django send_mail wrapper that will automatically add a plain text alternative to outgoing HTML emails.
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")