API Reference

This reference provides detailed information about the modules and classes in the django-templated-email-md package.

Backend

Backend that uses Django templates and allows writing email content in Markdown.

class templated_email_md.backend.MarkdownTemplateBackend(fail_silently=False, template_prefix=None, template_suffix=None, **kwargs)[source]

Bases: TemplateBackend

Backend that uses Django templates and allows writing email content in Markdown.

It renders the Markdown into HTML, wraps it with a base template, and inlines CSS styling. The plain text version is generated from the final HTML using html2text.

Cache settings (read from Django settings):

TEMPLATED_EMAIL_CACHE_RENDERED (bool): Enable render result caching. Default False. TEMPLATED_EMAIL_CACHE_TIMEOUT (int): Cache TTL in seconds. Default 300. TEMPLATED_EMAIL_CACHE_ALIAS (str): Django cache alias to use. Default “default”.

Parameters:
  • fail_silently (bool) –

  • template_prefix (str | None) –

  • template_suffix (str | None) –

  • kwargs (Any) –

__init__(fail_silently=False, template_prefix=None, template_suffix=None, **kwargs)[source]

Initialize the MarkdownTemplateBackend.

Parameters:
  • fail_silently (bool) – Whether to suppress exceptions and return a fallback response

  • template_prefix (str | None) – Prefix for template names

  • template_suffix (str | None) – Suffix for template names

  • kwargs (Any) – Additional keyword arguments

async asend(*args, **kwargs)[source]

Send an email asynchronously by wrapping the synchronous send().

Offloads the blocking render pipeline (Markdown conversion, CSS inlining via Premailer, html2text) and SMTP delivery to a thread pool via asgiref.sync.sync_to_async(), making it safe to await from async Django views, ASGI middleware, or async task queues.

thread_sensitive=True is used because send() may perform ORM writes (e.g. when create_link=True, django-templated-email persists a record), and thread-sensitive execution keeps that compatible with Django’s per-thread database connections.

All positional and keyword arguments are forwarded unchanged to send(). See send() for the full parameter reference.

Parameters:
  • args (Any) – Positional arguments forwarded to send().

  • kwargs (Any) – Keyword arguments forwarded to send().

Returns:

The return value of send() (typically None under the test email backend, matching Django’s locmem backend convention).

Return type:

Any

send(template_name, from_email, recipient_list, context, cc=None, bcc=None, fail_silently=False, headers=None, template_prefix=None, template_suffix=None, template_dir=None, file_extension=None, auth_user=None, auth_password=None, connection=None, attachments=None, create_link=False, **kwargs)[source]

Send an email using the Markdown template.

Overrides the send method to add support for a base URL, used by premailer to resolve relative URLs.

Parameters:
  • template_name (str | list | tuple) – The name of the Markdown template to render, or a list of names.

  • from_email (str) – The sender email address.

  • recipient_list (list[str]) – List of recipient email addresses.

  • context (dict[str, Any]) – The context dict used to render the template.

  • cc (list[str] | None) – Optional list of CC email addresses.

  • bcc (list[str] | None) – Optional list of BCC email addresses.

  • fail_silently (bool) – Whether to suppress SMTP errors.

  • headers (dict[str, str] | None) – Optional extra email headers.

  • template_prefix (str | None) – Optional prefix for template names.

  • template_suffix (str | None) – Optional suffix (file extension) for template names.

  • template_dir (str | None) – Optional directory override for template lookup.

  • file_extension (str | None) – Optional file extension override.

  • auth_user (str | None) – Optional SMTP authentication username.

  • auth_password (str | None) – Optional SMTP authentication password.

  • connection (Any) – Optional pre-opened email backend connection.

  • attachments (list | None) – Optional list of attachments to include.

  • create_link (bool) – Whether to persist a link record via django-templated-email.

  • kwargs (Any) – Additional keyword arguments forwarded to the parent send method. Pass base_url here to override the instance-level base URL for this call only.

Returns:

The return value of the parent send method (typically the number of messages sent, or None under the test email backend).

Return type:

Any