Skip to main content

MailCadence Engine

Production-grade, asynchronous bulk email dispatch and reporting engine built in Python 3.12+.

Overview

mail-cadence is a high-performance email dispatch engine that utilizes SQLite as its primary database backend for runtime configurations and execution history logging, while retaining full XML support for importing and exporting configuration definitions (tasks.xml and schedules.xml). It evaluates active schedule windows across timezones, dispatches scheduled email tasks concurrently with rate limiting and exponential backoff retry resilience, and sends a final Task Completion Status Report email upon completion.


Key Features

  • Python 3.12+ Standards: Built with strict type safety, asyncio.TaskGroup, StrEnum, pydantic v2, and pydantic-xml.
  • SQLite State Persistence: SQLite runtime database storing tasks, schedules, report settings, and detailed execution logs with Write-Ahead Logging (WAL) mode and busy timeout handling (30,000 ms).
  • Safe XML Import & Export: Built-in defusedxml protection against XXE and entity expansion attacks, supporting bidirectional conversion between XML documents and SQLite data models.
  • Timezone-Aware Throttling & Idempotency: Hourly schedule windows with zoneinfo time zone awareness, midnight-spanning time calculation, window-level idempotency protection (last_status == SUCCESS), and token bucket rate limiting.
  • Async SMTP Dispatch & Retries: High-concurrency SMTP dispatch with aiosmtplib, asyncio.Semaphore, connection pooling, exponential backoff retries on transient errors, and --dry-run simulation mode.
  • Jinja2 Templating: Templated task emails with path traversal defense and auto-escaped context variables, alongside consolidated HTML/plain-text batch summary reports.

Prerequisites & Installation

Requirements

  • Python >= 3.12
  • pip package manager

Installation Instructions

Clone the repository and install mail-cadence along with its development dependencies:

# Install in editable mode with development dependencies
python3 -m pip install -e ".[dev]"

Or use the provided Makefile:

make install

Configuration Reference

mail-cadence is configured through environment variables (or a .env file) for SMTP server options and database location, alongside XML or database settings.

Environment Variables (Settings)

Supported environment settings defined in mail_cadence.models.Settings:

Variable Default Description
SMTP_HOST localhost Hostname or IP address of the SMTP server
SMTP_PORT 1025 Port number for the SMTP server
SMTP_USER None Username for SMTP authentication (optional)
SMTP_PASSWORD None Password for SMTP authentication (optional)
SMTP_USE_TLS false Enable direct TLS connection (true/false)
SMTP_START_TLS false Enable STARTTLS command upgrade (true/false)
SMTP_TIMEOUT 30.0 Timeout in seconds for SMTP operations
MAIL_CADENCE_DB mail_cadence.db Path to SQLite database file

CLI Usage Guide (mail-cadence)

The package provides the mail-cadence CLI executable (as well as python -m mail_cadence.cli).

1. Main Dispatch Command

Executes the main bulk mailer dispatch pipeline.

mail-cadence [OPTIONS]

Flags & Options

Option Short Type Default Description
--tasks-xml -t PATH None Optional path to tasks XML file to seed/upsert database
--schedule-xml -s PATH None Optional path to schedule XML file to seed/upsert database
--db -b PATH mail_cadence.db Path to SQLite database file (overrides MAIL_CADENCE_DB)
--dry-run -d FLAG false Execute workflow in simulation mode without sending network SMTP requests
--verbose -v FLAG false Enable verbose debug logging output

Exit Codes

  • 0: Successful execution or no tasks were eligible for processing.
  • 1: Configuration or database error encountered (e.g. invalid file format, database connection failure).
  • 2: One or more tasks failed execution during the dispatch batch.

Example Dispatch Commands

# Execute dispatch and seed XML configurations if database is empty or needs updates
mail-cadence --tasks-xml config/samples/tasks.xml --schedule-xml config/samples/schedules.xml

# Run dispatch in dry-run mode using an existing SQLite database
mail-cadence --db mail_cadence.db --dry-run --verbose

2. XML Import Command (import-xml)

Imports task definitions and schedule rules from XML configuration files into the SQLite database.

mail-cadence import-xml [OPTIONS]

Options

Option Short Type Default Description
--tasks-xml -t PATH None Path to tasks configuration XML file
--schedule-xml -s PATH None Path to schedule configuration XML file
--db -b PATH mail_cadence.db Target SQLite database file path
--mode -m CHOICE upsert Import mode: upsert (update/insert) or replace (clear and reload)

Example

mail-cadence import-xml --tasks-xml config/samples/tasks.xml --schedule-xml config/samples/schedules.xml --mode upsert

3. XML Export Command (export-xml)

Exports current task definitions, schedules, and report settings from the SQLite database back into XML files.

mail-cadence export-xml [OPTIONS]

Options

Option Short Type Default Description
--tasks-xml -t PATH None Destination path for exported tasks XML
--schedule-xml -s PATH None Destination path for exported schedules XML
--db -b PATH mail_cadence.db Source SQLite database file path

Example

mail-cadence export-xml --tasks-xml exported_tasks.xml --schedule-xml exported_schedules.xml

Development & Quality Gates

The project maintains strict code quality standards enforced via Makefile commands:

# Run unit and integration test suite with coverage
make test

# Run code style and linting checks (Ruff & Mypy)
make lint

# Run dead code detection (Vulture)
make dead-code

# Run code complexity analysis (Radon)
make complexity

# Run dependency vulnerability audit (pip-audit)
make audit

# Run all quality gate checks in sequence
make quality-gate

Architectural Deep Dive

For detailed technical specifications, database entity-relationship diagrams (ERD), scheduling algorithms, Mermaid state/sequence diagrams, and security mechanics, see docs/ARCHITECTURE.md.

Metadata

Release files for mail-cadence 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mail-cadence 0.3.0
File Size Uploaded Provenance
mail_cadence-0.3.0.tar.gz 54.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mail-cadence 0.3.0
File Interpreter ABI Platform
mail_cadence-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 97.9 kB

Release files / mail_cadence-0.3.0.tar.gz

Download URL mail_cadence-0.3.0.tar.gz
Size 54.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b58c45f8cba0f0c622ce3c5b6ecb0aaad17c2d51b7beb5fbe32160752cd33cf3
BLAKE2b-256 checksum
How to use checksums
877fac568eeefc9a4f0bbf4d93342b571c1a50eee0540dc18cae6834d9379ec6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / mail_cadence-0.3.0-py3-none-any.whl

Download URL mail_cadence-0.3.0-py3-none-any.whl
Size 43.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36f9464b2a057ea65b91fefaaaeec04156987d86167a6c3cf91ef7bec16c4c66
BLAKE2b-256 checksum
How to use checksums
558e0497f5bc8690b67deff78394c85490af19ddaa9a223fd6e9a8562c74c8ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Security for mail-cadence 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mail_cadence-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page