Tim,
You don't need OS.open. You can do this by creating an html template first, and importing it using the get_template method. In your
view, add something along the lines of :
app/view.py
from django.core.mail import EmailMultiAlternatives
from django.http import HttpResponse
from django.template.loader import get_template
def send_mail(request):
text = get_template('email_template.txt')
html = get_template('email_template.html')
data = {'templating variable': data_var}
# If Client cant receive html mails, it will receive the text
# only version.
# Render the template with the data
content_txt = text.render(data)
content_html = html.render(data)
# Send mail
msg = EmailMultiAlternatives(subject, content_text, from_email, [to])
msg.attach_alternative(content_html, "text/html")
msg.send()
Note: You don't need Context for Djange 1.10+. In Django 1.8+, the template's render method takes a dictionary for the context parameter. Support for passing a Context instance is deprecated, and gives an error in Django 1.10+.