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, andpydantic-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
defusedxmlprotection against XXE and entity expansion attacks, supporting bidirectional conversion between XML documents and SQLite data models. - Timezone-Aware Throttling & Idempotency: Hourly schedule windows with
zoneinfotime 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-runsimulation 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.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mail_cadence-0.2.0.tar.gz | 50.5 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mail_cadence-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 88.6 kB
Release files / mail_cadence-0.2.0.tar.gz
| Download URL | mail_cadence-0.2.0.tar.gz |
|---|---|
| Size | 50.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7d34564e2cbb714b0b420f95bfd9b705507c058091033b0f139f1352b2c5c4ab
|
|
BLAKE2b-256 checksum How to use checksums |
cfa43d21fe70f46c9250b3ea2d359eb00acaefdd1cfca678ea04c64cf34bc844
|
| 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 logRelease files / mail_cadence-0.2.0-py3-none-any.whl
| Download URL | mail_cadence-0.2.0-py3-none-any.whl |
|---|---|
| Size | 38.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91823e8f871d3124df19c9a1a00e0dc2843f77a0b7e220ee019836ba03cb72c3
|
|
BLAKE2b-256 checksum How to use checksums |
a00ce953e3d5cb6e5ada520cab484a16389c00df563c5ab94c52d0e3296150e1
|
| 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 logSecurity for mail-cadence 0.2.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.
Attestation for mail_cadence-0.2.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 logA 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.