Skip to content

Messaging

send_templated_mail

Renders and sends an email from a set of template files sharing a common prefix, mirroring the template convention used by django-allauth's AccountAdapter.render_mail so non-authentication emails follow the same pattern as auth emails.

Parameter Type Default Description
template_prefix str — Prefix used to resolve the subject/text/html templates (see below)
context dict — Context passed to all three templates, plus current_site
recipient_list list — List of recipient email addresses
from_email str None Sender address; falls back to settings.DEFAULT_FROM_EMAIL

Required templates

Template Purpose
{template_prefix}_subject.txt Rendered, joined to a single line, and stripped to form the subject
{template_prefix}_message.txt Plain-text email body

Optional template

Template Purpose
{template_prefix}_message.html HTML alternative, attached via attach_alternative if the template exists
send_templated_mail(
    template_prefix="emails/order_shipped",
    context={"order": order},
    recipient_list=[order.customer.email],
)

This looks for emails/order_shipped_subject.txt, emails/order_shipped_message.txt, and (optionally) emails/order_shipped_message.html.

Note

current_site (via Site.objects.get_current()) is always injected into the template context automatically, alongside whatever you pass in context.

Note

If {template_prefix}_message.html doesn't exist, the missing template is silently ignored and a plain-text-only email is sent.