Skip to content

Instantly share code, notes, and snippets.

@ericflo
Created March 23, 2012 21:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericflo/2175106 to your computer and use it in GitHub Desktop.
Save ericflo/2175106 to your computer and use it in GitHub Desktop.
Send a templated mail
from django.conf import settings
from django.template import Context, loader
from django.core.mail import send_mail
def send_template_mail(slug, context, recipient_list, from_email=settings.DEFAULT_FROM_EMAIL):
if isinstance(recipient_list, basestring):
recipient_list = [recipient_list]
if not isinstance(context, Context):
context = Context(context)
subject_tmpl = loader.get_template('mail/%s/subject.txt' % (slug,))
body_tmpl = loader.get_template('mail/%s/body.txt' % (slug,))
subject = subject_tmpl.render(context)
body = body_tmpl.render(context)
send_mail(subject, body, from_email, recipient_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment