Sending email with html in Django 1.7
django, email, html, python
Solution
`render_to_string` : which loads a template, renders it and returns the resulting `string`. `html_message` : If `html_message` is provided, the default message replaced with Html message.
mail/html-message.html
Hi {{ first_name }}.
This is your {{ email }}
Thank you
views.py
def mail_function(request):
subject = 'Test Mail'
from = 'info@domain.com'
to = 'to@domain.com'
c = Context({'email': email,
'first_name': first_name})
html_content = render_to_string('mail/html-message.html', c)
txtmes = render_to_string('mail/text-message.html', c)
send_mail(subject,
txtmes,
from,
[to],
fail_silently=False,
html_message=html_content)
Problem
In send_mail() we have one new parameter - `html_message`. Docs I have email.html file and I want to send html version of my message. I can't find any example for Django 1.7. Can you show me a way, how to do this? Does I need to use os.open() my html file? Thanks!