Skip to main content

CI PyPI version Python versions License Ruff Typed

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, a durable claim per task and window occurrence (one automatic send per window occurrence until the task is changed or reset, also across processes on one host; see Delivery Guarantees), and token bucket rate limiting.
  • Async SMTP Dispatch & Retries: High-concurrency SMTP dispatch with aiosmtplib, asyncio.Semaphore, connection pooling, per-recipient retries of transient errors, and --dry-run simulation mode. A delivery with an unknown outcome is never resent automatically.
  • Jinja2 Templating: Templated task emails with path traversal defense and auto-escaped context variables, alongside consolidated HTML/plain-text batch summary reports.
  • Web Panel: FastAPI + HTMX panel for tasks, schedules, template previews, execution history and operator review.

Installation

Requires Python >= 3.12.

python3 -m pip install mail-cadence

For development (editable install, quality gates), see docs/DEVELOPMENT.md.

Quick Start

The sample configuration lives in config/samples/ of the repository and uses the built-in templates.

# 1. Load tasks and schedules into a new database (mail_cadence.db)
mail-cadence import-xml --tasks-xml config/samples/tasks.xml --schedule-xml config/samples/schedules.xml

# 2. See what would be sent now, without sending anything
mail-cadence --dry-run --verbose

# 3. Send: set SMTP_HOST, SMTP_PORT and, for a login, SMTP_USER/SMTP_PASSWORD with TLS
mail-cadence

# 4. Open the web panel on http://127.0.0.1:8000
ADMIN_USER=admin ADMIN_PASSWORD='change-me' mail-cadence serve

Run step 3 from cron or a systemd timer, more often than the shortest window lasts: each run sends the tasks whose window is open and skips a task already sent in the current window occurrence, however often the command runs. Saving a changed task, Allow Resend and the Run button in the panel can send a task again; the exact guarantees and their limits are in Delivery Guarantees. The exit code tells the result (0 ok, 1 configuration error, 2 incomplete delivery, 3 unknown outcome to review, 4 report not sent).

Documentation

Document Contents
Configuration Environment variables, database upgrades, rules for tasks, schedules and templates
CLI reference Every command and option, the web panel and its security behaviour
Operations Exit codes, monitoring with mail-cadence status, delivery guarantees, status report retries, reviewing unknown deliveries
Deployment systemd units, dispatch timer, nginx with HTTPS, fail2ban, backups
Python API Updating tasks and running a dispatch from Python
Architecture Modules, database schema, XML mapping, validation rules, internals
Development Quality gates, CI and releases

All documents are listed in docs/README.md.

When to Use mail-cadence

mail-cadence is designed for environments where plain cron scripts lack state tracking, rate control, and observability, while full distributed task queues (Celery + Redis + PostgreSQL) introduce unnecessary operational overhead.

  • Scheduled Infrastructure & Telemetry Digests: Dispatch daily or shift-based operational reports (e.g., disk/log audits, security scan summaries, SCADA/IoT telemetry aggregations, or energy yield forecasts) within designated time windows. Each window occurrence is claimed in the database, so mail-cadence can run every few minutes from cron or a systemd.timer and a task is still sent once per window occurrence. The timer checks the schedule, not the source system: the data and templates must be ready when the window opens. A report that cannot be rendered fails for that window occurrence and is not retried when the data arrives later; edit the task or use Allow Resend to send it again.
  • SMTP Rate-Limit Protection (Paced Dispatch): Standard corporate and ISP SMTP relays (such as Microsoft 365, Google Workspace, or local Postfix instances) enforce strict per-minute message caps and concurrent connection limits. mail-cadence paces delivery attempts per window occurrence using a TokenBucketRateLimiter (rate_limit_per_min) and an asyncio.Semaphore (max_concurrency). This lowers the risk of 421/451 throttling, but it is not a limit for the whole SMTP account: several windows, concurrent processes and other applications using the same account add up.
  • Legacy System & ERP Email Gateway via XML: Many industrial, billing, and legacy enterprise workflows export batch definitions as XML files to a shared directory rather than calling REST APIs. The import-xml (upsert / replace) command validates these definitions with defusedxml and pydantic-xml before syncing them into SQLite for scheduled delivery.
  • GitOps-Driven Internal Notifications: Teams can version-control their communication schedules (schedules.xml) and task definitions (tasks.xml) in Git (automatic sends start only on the listed days and hours, e.g. days_of_week="mon,tue,wed,thu,fri"; manual runs and status reports are not bound to windows) while operators use the built-in FastAPI + HTMX panel (mail-cadence serve) to preview Jinja2 templates, inspect execution logs, or trigger ad-hoc runs.
  • Zero-Broker Sidecar for Lightweight Applications: Acts as a self-contained email subsystem backed by a single SQLite (WAL) file for on-premise or single-node deployments where data privacy and minimal RAM footprint are required.

License

MIT, see LICENSE.

Metadata

Release files for mail-cadence 0.10.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.10.0
File Size Uploaded Provenance Actions
mail_cadence-0.10.0.tar.gz 315.1 kB With provenance Details for mail_cadence-0.10.0.tar.gz

Built distribution (wheel)

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

Total release size: 554.3 kB

Release files / mail_cadence-0.10.0.tar.gz

Download URL mail_cadence-0.10.0.tar.gz
Size 315.1 kB
Tags Source
SHA-256 checksum
How to use checksums
00cc10498410ea8e0d835a778d6ca1e30f65e44293780dac3c45d7638f460859
BLAKE2b-256 checksum
How to use checksums
1511ddbe6a993e329f752a9487b908d8fd03e0f93dc9c9ebec8c779c1c80e504
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 30, 2026.

Transparency log

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

Download URL mail_cadence-0.10.0-py3-none-any.whl
Size 239.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81630d359c153bb7e41c91cf6c150001b7eede8be3bc3ab4a78cc2c7536ab805
BLAKE2b-256 checksum
How to use checksums
f1cb10f802c0ca581f24bfc0332cdf381bd752b3a147f6af31a0180ba96ab534
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 30, 2026.

Transparency log

Security for mail-cadence 0.10.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mail_cadence-0.10.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 30, 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