5π
β
In Django 1.7, send_mail()
accepts an html_message
argument:
If html_message is provided, the resulting email will be
a multipart/alternative email with message as the text/plain content
type and html_message as the text/html content type.
Example:
send_mail('Subject', 'Content', 'sender@example.com', ['nobody@example.com'],
html_message='This is <b>HTML</b> Content')
For Django<1.7, you can either use a solution suggested here, or use a third-party, like django-email-html.
Also, there is another third-party package that you should consider using β django-mail-templated. It basically allows you to describe your email messages in django templates. Additionally, it allows to send html messages defined in html
block in the template.
For example:
-
create a template
{% block subject %} Email subject {% endblock %} {% block body %} This is a plain text. {% endblock %} {% block html %} This is <b>HTML</b> Content. {% endblock %}
-
and send it:
from mail_templated import send_mail send_mail('my_template.tpl', {}, from_email, [user.email])
Hope that helps.
π€alecxe
Source:stackexchange.com