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:
StrEnumTypes of email templates.
- TRANSACTIONAL = 'transactional'
- NOTIFICATION = 'notification'
- NEWSLETTER = 'newsletter'
- MARKETING = 'marketing'
- SYSTEM = 'system'
- __new__(value)
- class EmailTemplate[source]
Bases:
AuditBaseDatabase-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.
- render_content_text(context=None)[source]
Render plain text email content with context variables.
- render_content_html(context=None)[source]
Render HTML email content with context variables.
- validate_templates()[source]
Validate all template strings for syntax errors.
- __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:
AuditBaseLog 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:
BaseModelBase 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:
EmailTemplateBaseSchema 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:
BaseModelSchema 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:
EmailTemplateBaseSchema 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:
BaseModelSchema 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:
BaseModelSchema 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:
BaseModelBase 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:
EmailLogBaseSchema 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:
EmailLogBaseSchema 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:
BaseModelSchema 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:
BaseModelSchema 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:
BaseModelSchema 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].