Mailing Lists

Mailing list management and subscriptions.

Module Contents

Models

Mailing domain models.

This module provides database-driven email templates that can be rendered with context variables using Jinja2. Templates can be managed via the admin interface and used for newsletters, notifications, and transactional emails.

class EmailTemplateType[source]

Bases: StrEnum

Types of email templates.

TRANSACTIONAL = 'transactional'
NOTIFICATION = 'notification'
NEWSLETTER = 'newsletter'
MARKETING = 'marketing'
SYSTEM = 'system'
__new__(value)
class EmailTemplate[source]

Bases: AuditBase

Database-driven email template.

Stores email templates with Jinja2 content that can be rendered with context variables. Supports both plain text and HTML content.

internal_name

Unique identifier used in code (e.g., “job_approved”)

display_name

Human-readable name for admin UI

description

Description of when/how this template is used

template_type

Category of email (transactional, newsletter, etc.)

subject

Email subject (supports Jinja2 templating)

content_text

Plain text email body (supports Jinja2 templating)

content_html

HTML email body (supports Jinja2 templating, optional)

is_active

Whether this template can be used

default_context

Default context variables as JSON

internal_name: Mapped[str]
display_name: Mapped[str]
description: Mapped[str | None]
template_type: Mapped[EmailTemplateType]
subject: Mapped[str]
content_text: Mapped[str]
content_html: Mapped[str | None]
is_active: Mapped[bool]
render_subject(context=None)[source]

Render the email subject with context variables.

Parameters:

context (Mapping[str, Any] | None) – Dictionary of variables to use in template

Return type:

str

Returns:

Rendered subject string

Raises:

TemplateSyntaxError – If template syntax is invalid

render_content_text(context=None)[source]

Render plain text email content with context variables.

Parameters:

context (Mapping[str, Any] | None) – Dictionary of variables to use in template

Return type:

str

Returns:

Rendered plain text content

Raises:

TemplateSyntaxError – If template syntax is invalid

render_content_html(context=None)[source]

Render HTML email content with context variables.

Parameters:

context (Mapping[str, Any] | None) – Dictionary of variables to use in template

Return type:

str | None

Returns:

Rendered HTML content, or None if no HTML template

Raises:

TemplateSyntaxError – If template syntax is invalid

validate_templates()[source]

Validate all template strings for syntax errors.

Return type:

list[str]

Returns:

List of error messages (empty if valid)

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

created_at: Mapped[datetime.datetime]

Date/time of instance creation.

id: Mapped[UUID]

UUID Primary key column.

updated_at: Mapped[datetime.datetime]

Date/time of instance last update.

class EmailLog[source]

Bases: AuditBase

Log of sent emails for audit and debugging.

Tracks all emails sent through the system with their status, recipient, and template information.

template_name

Internal name of template used (or “custom”)

recipient_email

Email address of recipient

subject

Actual rendered subject sent

status

Delivery status (pending, sent, failed, bounced)

error_message

Error details if failed

sent_at

Timestamp when email was sent

metadata

Additional metadata as JSON (e.g., user_id, context)

template_name: Mapped[str]
recipient_email: Mapped[str]
subject: Mapped[str]
status: Mapped[str]
error_message: Mapped[str | None]
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

created_at: Mapped[datetime.datetime]

Date/time of instance creation.

id: Mapped[UUID]

UUID Primary key column.

updated_at: Mapped[datetime.datetime]

Date/time of instance last update.

Schemas

Mailing domain Pydantic schemas.

class EmailTemplateBase[source]

Bases: BaseModel

Base schema for email templates.

internal_name: str
display_name: str
description: str | None
template_type: EmailTemplateType
subject: str
content_text: str
content_html: str | None
is_active: bool
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class EmailTemplateCreate[source]

Bases: EmailTemplateBase

Schema for creating an email template.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class EmailTemplateUpdate[source]

Bases: BaseModel

Schema for updating an email template.

display_name: str | None
description: str | None
template_type: EmailTemplateType | None
subject: str | None
content_text: str | None
content_html: str | None
is_active: bool | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class EmailTemplateRead[source]

Bases: EmailTemplateBase

Schema for reading an email template.

model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

id: UUID
created_at: datetime
updated_at: datetime
class EmailTemplatePreview[source]

Bases: BaseModel

Schema for previewing rendered email template.

subject: str
content_text: str
content_html: str | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class EmailTemplateValidation[source]

Bases: BaseModel

Schema for template validation results.

is_valid: bool
errors: list[str]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class EmailLogBase[source]

Bases: BaseModel

Base schema for email logs.

template_name: str
recipient_email: EmailStr
subject: str
status: str
error_message: str | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class EmailLogCreate[source]

Bases: EmailLogBase

Schema for creating an email log entry.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class EmailLogRead[source]

Bases: EmailLogBase

Schema for reading an email log entry.

model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

id: UUID
created_at: datetime
updated_at: datetime
class SendEmailRequest[source]

Bases: BaseModel

Schema for sending an email via template.

template_name: str
to_email: EmailStr
context: dict[str, Any]
cc: list[EmailStr] | None
bcc: list[EmailStr] | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class SendEmailResponse[source]

Bases: BaseModel

Schema for send email response.

success: bool
message: str
log_id: UUID | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class BulkSendEmailRequest[source]

Bases: BaseModel

Schema for sending bulk emails.

template_name: str
recipients: list[EmailStr]
context: dict[str, Any]
per_recipient_context: dict[str, dict[str, Any]] | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class BulkSendEmailResponse[source]

Bases: BaseModel

Schema for bulk send email response.

total: int
sent: int
failed: int
log_ids: list[UUID]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Repositories

Services

Controllers

Dependencies