Skip to content

Instantly share code, notes, and snippets.

@BenAtWide
Last active March 15, 2017 11:24
Show Gist options
  • Save BenAtWide/79ddf014a2610006791864103cdb2d28 to your computer and use it in GitHub Desktop.
Save BenAtWide/79ddf014a2610006791864103cdb2d28 to your computer and use it in GitHub Desktop.
Send an email generated from a template.
from django.core.mail import send_mail
from django.template.loader import render_to_string
def send_rendered_email(recipients=[]):
# send an email to a list of recipients - NB it's a list!
ctx = {'var': 'val'} # context dict
text_body = render_to_string('path/to/template.txt', ctx)
html_body = render_to_string('path/to/template.html', ctx)
if send_mail("My subject", text_body, from_email, recipients, html_message=html_body):
return "Mail sent"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment