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, 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-runsimulation 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-cadencecan run every few minutes fromcronor asystemd.timerand 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-cadencepaces delivery attempts per window occurrence using aTokenBucketRateLimiter(rate_limit_per_min) and anasyncio.Semaphore(max_concurrency). This lowers the risk of421/451throttling, 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 withdefusedxmlandpydantic-xmlbefore 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.9.3
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 | Actions |
|---|---|---|---|---|
| mail_cadence-0.9.3.tar.gz | 295.5 kB | With provenance | Details for mail_cadence-0.9.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mail_cadence-0.9.3-py3-none-any.whl | Python 3 | none | any | Details for mail_cadence-0.9.3-py3-none-any.whl |
Total release size: 527.3 kB
Release files / mail_cadence-0.9.3.tar.gz
| Download URL | mail_cadence-0.9.3.tar.gz |
|---|---|
| Size | 295.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b15f8a0b989c36745073a48618619e381c1b63b0d0dd4d01e4280ba3fe98f9d
|
|
BLAKE2b-256 checksum How to use checksums |
78395cce9f1ec403076f06499f435bf009c837178b60e47ce0769e9f2e3c35a6
|
| 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 29, 2026.
Transparency logRelease files / mail_cadence-0.9.3-py3-none-any.whl
| Download URL | mail_cadence-0.9.3-py3-none-any.whl |
|---|---|
| Size | 231.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c1dc7644697a6513e3014a5db49da6cb607241d725d265a32b3533f06ebc8d54
|
|
BLAKE2b-256 checksum How to use checksums |
b9e88c519c1f341ee66b54128572091b744994cc189f2c8d325249c89c9c3975
|
| 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 29, 2026.
Transparency logSecurity for mail-cadence 0.9.3
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.
Attestation for mail_cadence-0.9.3.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 29, 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.