- Install
pip install django-bs-email
- Add to
INSTALLED_APPS
INSTALLED_APPS = [
# ...
"django_bootstrap_email",
]
- Use the
bootstrap_email
template tag in your Django template
{% load bootstrap_email %}
{% bootstrap_email %}
<body class="bg-light">
<div class="container">
<div class="card my-10">
<div class="card-body">
<p>
{{ message }}
</p>
</div>
</div>
</div>
</body>
{% end_bootstrap_email %}
- Create the email and send it
context = {
"message": "Hello World!",
}
# you should always include a plain text version of the HTML email
text_content = context["message"]
html_content = render_to_string("path/to/template.html", context)
email_message = EmailMultiAlternatives(
subject="Greetings",
body=text_content,
from_email="[email protected]",
to=["[email protected]"],
)
email_message.attach_alternative(html_content, "text/html")
email_message.send()
This will produce a complete HTML email that renders consistently across email clients: