MailForensics
Trace outbound email through logs, queues, filters and relays.
MailForensics links application events, Postfix queue IDs, Message-IDs, filter activity and relay responses into a delivery timeline. It also checks live queue state when available and marks stages for which logs are missing.
Project page · Engineering note · PyPI · Releases
Quick start
Install from PyPI:
python -m pip install mailforensics
See the tool without needing a mail server:
mailforensics demo
Or inspect the local environment:
mailforensics doctor
Python 3.11+ is required. Live journald and Postfix queue inspection are intended for Linux; file, JSONL, and saved-queue analysis can be used independently.
When it is useful
Use MailForensics when:
- an application says it submitted mail, but the message never seems to arrive;
- a message changes queue ID during a
queued ashandoff; - a deferred message may or may not still be present in the live queue;
- Rspamd, a milter, Postfix, and the next relay each tell only part of the story;
- you need to know exactly what the logs prove — without turning missing evidence into a guessed root cause.
What it does
MailForensics can:
- correlate Message-ID, Postfix queue IDs,
queued ashandoffs, and applicationcorrelation_idvalues; - parse Postfix, Rspamd, milter, RFC 3164/5424, and journald-style evidence;
- inspect the current Postfix queue with
postqueue -j; - distinguish historical queue activity from what is still queued now;
- explain
sent,deferred,bounced, filter rejection, and evidence gaps; - show per-stage timing and the total observed trace window;
- emit human-readable, JSON, and self-contained HTML reports;
- load additional parsers through the
mailforensics.parsersplugin entry point.
It is deliberately not an email-header analyzer and not an always-on monitoring platform.
Example
mailforensics explain \
--journal \
--since '20 minutes ago' \
--live-queue \
--message-id '<invite-123@example.net>'
Example output:
MAILFORENSICS EXPLAIN
query: message-id=<invite-123@example.net>
status: deferred
Pipeline
● APP app/invite
│ 92ms
▼
● POSTFIX postfix/cleanup
│ 34ms
▼
● FILTER Rspamd: no action
│ 11ms
▼
● QUEUE queue 0DC461ACD87
│ 842ms
▼
◐ RELAY deferred via mx.example.net
│ 2.12m
▼
◐ QUEUE NOW still present in deferred queue
Assessment
outcome: queued-for-retry
last stage: postfix-queue:deferred
confidence: high
Postfix deferred delivery and the message is still present in the live queue.
Caveat: Postfix can retry later according to its queue schedule.
A missing log entry is not proof that the corresponding component failed.
Commands
| Command | Purpose |
|---|---|
mailforensics explain |
Compact pipeline, latency, and assessment |
mailforensics trace |
Full normalized evidence timeline |
mailforensics demo |
Built-in zero-setup scenarios |
mailforensics doctor |
Check local capabilities and permissions |
mailforensics parsers |
List built-in and external parser adapters |
mailforensics completion |
Generate Bash, Zsh, or Fish completion |
The default CLI form also accepts trace options directly:
mailforensics --file /var/log/mail.log --queue 0DC461ACD87
Evidence sources
A single run can combine multiple sources:
- classic syslog mail logs;
- ISO/journald-style logs;
- RFC 5424 syslog;
- direct
journalctlcollection; - live or saved
postqueue -jsnapshots; - Rspamd task/proxy logs;
- Postfix milter reject/discard events;
- structured JSONL application or gateway events;
- external parser plugins.
Live queue state
mailforensics explain \
--journal \
--since '2 hours ago' \
--live-queue \
--queue 0DC461ACD87
Or inspect a saved snapshot:
postqueue -j > queue.jsonl
mailforensics explain \
--queue-file queue.jsonl \
--queue 0DC461ACD87
This lets MailForensics distinguish an old deferred event from a message that is still present in the queue now.
Application and gateway events
Applications can join the trace without a custom parser by emitting JSON Lines:
{"timestamp":"2026-10-04T12:00:00+00:00","source":"app","stage":"invite","kind":"submitted","correlation_id":"invite-42","message_id":"invite-123@example.net","recipient":"tester@example.com","status":"submitted"}
Then correlate it with infrastructure evidence:
mailforensics explain \
--events app-mail-events.jsonl \
--journal \
--since '30 minutes ago' \
--correlation-id invite-42
See structured application events for the supported schema.
Correlation model
MailForensics expands a trace through explicit identifiers rather than timestamp proximity:
correlation_id
│
▼
Message-ID
│
▼
Postfix queue ID ─── queued as ─── next queue ID
│
├────────────── Rspamd / milter
├────────────── live postqueue
└────────────── SMTP / LMTP / local delivery
Timestamp proximity alone is never enough to merge two messages.
See correlation model for details.
Evidence semantics
MailForensics intentionally keeps a few boundaries explicit:
- Postfix
status=sentmeans the configured next hop accepted the message. - It does not prove inbox placement.
- A live queue entry proves the queue item existed at capture time, not why delivery is delayed.
- A later delivery result takes precedence over an earlier retry state.
- Rspamd rejection and Postfix milter rejection remain separate pieces of evidence.
- Missing evidence stays unknown instead of becoming a green check or a fabricated root cause.
Reports and automation
Machine-readable JSON:
mailforensics explain \
--journal \
--since today \
--queue ABC123 \
--json
Self-contained HTML report:
mailforensics explain \
--journal \
--since '30 minutes ago' \
--queue ABC123 \
--html mailforensics-report.html
The HTML report contains no external JavaScript or assets.
Demo fixtures
The repository includes small sanitized evidence sets for:
- delivered mail;
- deferred mail;
- filter rejection;
- a trace that stops before Postfix.
Example:
mailforensics explain \
--file examples/fixtures/deferred/mail.log \
--queue-file examples/fixtures/deferred/queue.jsonl \
--queue 0DC461ACD87
Parser plugins
Third-party packages can register parser adapters with:
[project.entry-points."mailforensics.parsers"]
my_gateway = "my_mailforensics_plugin:parse"
Parsers should emit mailforensics.model.Event objects and only attach identifiers that are supported by the source evidence.
See parser plugin API.
Shell completion
mailforensics completion bash
mailforensics completion zsh
mailforensics completion fish
Convenience stubs are also available under completions/.
Exit codes
| Code | Meaning |
|---|---|
0 |
Trace found / command succeeded |
1 |
No matching trace, or doctor found a hard failure |
2 |
Invocation or runtime error |
Development
git clone https://github.com/artur-panek/mailforensics.git
cd mailforensics
python -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[dev]"
ruff check .
pytest
CI also builds the wheel and source distribution, validates package metadata with twine check --strict, and installs the built wheel in a clean virtual environment.
See CONTRIBUTING.md for contribution guidelines.
Origin
MailForensics started during a rage-fix after debugging an invite path that was accepted by one layer and then seemed to disappear in the next.
The project grew around one rule:
Report what the evidence proves. Make uncertainty explicit.
License
MIT
Metadata
Release files for mailforensics 0.5.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 |
|---|---|---|---|---|
| mailforensics-0.5.3.tar.gz | 91.7 kB | With provenance | Details for mailforensics-0.5.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mailforensics-0.5.3-py3-none-any.whl | Python 3 | none | any | Details for mailforensics-0.5.3-py3-none-any.whl |
Total release size: 127.0 kB
Release files / mailforensics-0.5.3.tar.gz
| Download URL | mailforensics-0.5.3.tar.gz |
|---|---|
| Size | 91.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ea81233a725254a4e287da006e43fe699f175ee061e1e73fbf89d4e2b31ca72
|
|
BLAKE2b-256 checksum How to use checksums |
6b10670c2eb57d3d3f3fe474aaf07e6745ac46af6b512a8677a758952dc5a878
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 20, 2026.
Transparency logRelease files / mailforensics-0.5.3-py3-none-any.whl
| Download URL | mailforensics-0.5.3-py3-none-any.whl |
|---|---|
| Size | 35.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7288b523f79cb3995f19ca85643f39be5d3a8e7aa175e93f2772f1ef21109f40
|
|
BLAKE2b-256 checksum How to use checksums |
e3e37c253384704b70124581a5ccbed338930236e01e86630bdb0923b6828208
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 20, 2026.
Transparency logSecurity for mailforensics 0.5.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 mailforensics-0.5.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 20, 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.