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 (at most one send per window, also across processes on one host), 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, for example every 10 minutes: each task is sent at most once per window occurrence, however often the command runs. 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, 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) strictly within designated time windows. Because window execution is idempotent, mail-cadence can be invoked repeatedly by cron or systemd.timer (e.g., every 10 minutes to wait for upstream data availability) while guaranteeing the report is sent at most once per active window.
  • 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 outgoing batches using a per-window TokenBucketRateLimiter (rate_limit_per_min) and asyncio.Semaphore (max_concurrency), preventing 421/451 throttling errors and account lockouts.
  • 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—enforcing business-hours-only delivery (days_of_week="mon,tue,wed,thu,fri")—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.9.2

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.9.2
File Size Uploaded Provenance Actions
mail_cadence-0.9.2.tar.gz 285.8 kB With provenance Details for mail_cadence-0.9.2.tar.gz

Built distribution (wheel)

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

Total release size: 510.5 kB

Release files / mail_cadence-0.9.2.tar.gz

Download URL mail_cadence-0.9.2.tar.gz
Size 285.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f156aae0cc6e0547d2ca66689091072f33590fd12f1adba67fc277b4ab8dd1b2
BLAKE2b-256 checksum
How to use checksums
d84d0cbd3071593985614025228c2da57626cfa023531591a99c40b574d324af
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 28, 2026.

Transparency log

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

Download URL mail_cadence-0.9.2-py3-none-any.whl
Size 224.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f7bd2f7aed57b2e6f7ec9d2d9ce5726578e6a82637f1e520cf47a5dd972cd50
BLAKE2b-256 checksum
How to use checksums
dc9fd31d6c8b3ded3807e090366926c9df3e8618d2b342d261558bdb0bab52e2
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 28, 2026.

Transparency log

Security for mail-cadence 0.9.2

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.9.2.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 28, 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