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.

send_bulk(payloads)

Send multiple 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]

class util.email.EmailPayload[source]ΒΆ

Immutable value object describing one outbound email.

subject[source]ΒΆ

Subject line.

to[source]ΒΆ

Recipients.

template_html[source]ΒΆ

Django template path for the HTML body.

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.

Ensures that mapping/sequence attributes are immutable wrappers or tuples.

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.

Returns:

Number of successfully delivered messages (0 or 1).

Parameters:
Return type:

int

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

Send multiple emails reusing one SMTP connection.

Parameters:

payloads (collections.abc.Iterable[EmailPayload])

Return type:

int