util.emailΒΆ

Email utility classes and functions for rendering and sending templates.

AttributesΒΆ

ClassesΒΆ

MailTemplate

Represents a template base path with helpers for .txt and .html variants.

MailTemplates

Registry of grouped mail templates.

EmailPayload

Immutable value object describing one outbound email.

FunctionsΒΆ

_render_bodies(tpl, context)

send_email(payload, *[, connection])

Send a single email with HTML + text alternative (from templates).

send_simple(*, subject, body, to[, cc, bcc, ...])

Send a plain-text email without using a HTML/txt template pair.

normalize_addresses(value)

Accept CSV string or iterable; return tuple of non-empty, trimmed emails.

send_bulk(payloads)

Send multiple template-based emails reusing one SMTP connection.

Module ContentsΒΆ

util.email.Attachment[source]ΒΆ
class util.email.MailTemplate[source]ΒΆ

Represents a template base path with helpers for .txt and .html variants.

key: str[source]ΒΆ
base: str[source]ΒΆ
label: str[source]ΒΆ
txt()[source]ΒΆ

Return the plain-text template path.

Return type:

str

html()[source]ΒΆ

Return the HTML template path.

Return type:

str

class util.email.MailTemplates[source]ΒΆ

Registry of grouped mail templates.

USER_WELCOME: ClassVar[MailTemplate][source]ΒΆ
USER_DELETE: ClassVar[MailTemplate][source]ΒΆ
CERTIFICATE_ISSUED: ClassVar[MailTemplate][source]ΒΆ
CERTIFICATE_REVOKED: ClassVar[MailTemplate][source]ΒΆ
GROUPS: ClassVar[collections.abc.Mapping[str, tuple[MailTemplate, Ellipsis]]][source]ΒΆ
classmethod get_user_templates()[source]ΒΆ

Return the list of user-related templates.

Return type:

list[MailTemplate]

classmethod get_certificate_templates()[source]ΒΆ

Return the list of certificate-related templates.

Return type:

list[MailTemplate]

classmethod all()[source]ΒΆ

Return all templates for all groups.

Return type:

list[MailTemplate]

classmethod get_by_key(key)[source]ΒΆ

Find a template by its key.

Parameters:

key (str)

Return type:

MailTemplate | None

class util.email.EmailPayload[source]ΒΆ

Immutable value object describing one outbound email.

subject[source]ΒΆ

Subject line.

to[source]ΒΆ

Recipients.

template_html[source]ΒΆ

Django template base (we render .txt and .html).

context[source]ΒΆ

Template context (wrapped as read-only).

from_email[source]ΒΆ

Optional override; defaults to settings.DEFAULT_FROM_EMAIL.

reply_to[source]ΒΆ

Optional Reply-To addresses.

cc[source]ΒΆ

Optional CC recipients.

bcc[source]ΒΆ

Optional BCC recipients.

attachments[source]ΒΆ

Optional sequence of (filename, bytes, mimetype).

headers[source]ΒΆ

Optional extra headers (e.g., {β€œX-Tag”: β€œwelcome”}).

subject: str[source]ΒΆ
to: tuple[str, Ellipsis][source]ΒΆ
template_html: MailTemplate[source]ΒΆ
context: collections.abc.Mapping[str, object][source]ΒΆ
from_email: str | None = None[source]ΒΆ
reply_to: tuple[str, Ellipsis] = ()[source]ΒΆ
cc: tuple[str, Ellipsis] = ()[source]ΒΆ
bcc: tuple[str, Ellipsis] = ()[source]ΒΆ
attachments: tuple[Attachment, Ellipsis] = ()[source]ΒΆ
headers: collections.abc.Mapping[str, str][source]ΒΆ
__post_init__()[source]ΒΆ

Validate and normalize fields after dataclass initialization.

Return type:

None

util.email._render_bodies(tpl, context)[source]ΒΆ
Parameters:
  • tpl (MailTemplate)

  • context (collections.abc.Mapping[str, object])

Return type:

tuple[str, str]

util.email.send_email(payload, *, connection=None)[source]ΒΆ

Send a single email with HTML + text alternative (from templates).

Parameters:
Return type:

int

util.email.send_simple(*, subject, body, to, cc=(), bcc=(), from_email=None, connection=None, attachments=())[source]ΒΆ

Send a plain-text email without using a HTML/txt template pair.

Parameters:
  • subject (str)

  • body (str)

  • to (collections.abc.Iterable[str])

  • cc (collections.abc.Iterable[str])

  • bcc (collections.abc.Iterable[str])

  • from_email (str | None)

  • connection (Any)

  • attachments (collections.abc.Iterable[Attachment])

Return type:

int

util.email.normalize_addresses(value)[source]ΒΆ

Accept CSV string or iterable; return tuple of non-empty, trimmed emails.

Parameters:

value (Any)

Return type:

tuple[str, Ellipsis]

util.email.send_bulk(payloads)[source]ΒΆ

Send multiple template-based emails reusing one SMTP connection.

Parameters:

payloads (collections.abc.Iterable[EmailPayload])

Return type:

int