Last active
March 15, 2017 11:24
-
-
Save BenAtWide/79ddf014a2610006791864103cdb2d28 to your computer and use it in GitHub Desktop.
Send an email generated from a template.
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.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