---
title: Emails That Prove They're Real
date: '2026-11-08'
description: 'A phisher can copy any footer word for word. So Mailingest''s footer carries a reference instead, and the proof lives with timestamp authorities.'
author: Pablo Fernandez
tags:
  - Email
  - Security
  - Timestamping
  - Merkle Trees
  - Rust
source: 'https://www.pablofr.com/blog/proving-an-email-is-genuine'
---
Every bank email ends with a paragraph that says the bank will never ask for your password. Every phishing email that copies the bank ends with the same paragraph, because copying it costs nothing. A footer that says "this email is secure" proves exactly as much as the person who typed it.

So when I added a security footer to [Mailingest](/blog/giving-an-inbox-to-each-agent), my mail platform, the question wasn't how to word it. It was what a footer can prove at all, when anyone can paste it into a message of their own. This is the answer it ships with today, and the first version I threw away to get there.

## A code per recipient

The first design, on October 26, gave every recipient their own code. A message to three people carried three codes, each 20 symbols from an alphabet with the confusable characters taken out:

```rust:crates/crypto/src/human_code.rs /248/
const ALPHABET: &[u8] = b"23456789ABCDEFGHJKMNPQRSTUVWXYZ";

pub fn generate(len: usize) -> String {
    let mut symbols = Vec::with_capacity(len);
    while symbols.len() < len {
        for byte in crate::random_bytes::<32>() {
            // Rejection sampling: 248 = 8 × 31, so every symbol is as likely.
            if byte < 248 && symbols.len() < len {
                symbols.push(ALPHABET[(byte % 31) as usize] as char);
            }
        }
    }
    grouped(&symbols.into_iter().collect::<String>())
}
```

The recipient typed the code into a verification page and saw who sent the message, when, and to which address, partly masked. The point of one code per person: a scammer who copies a real code into a fake email shows the victim a page that names someone else's address. Only a hash of each code was stored. Later the same week the hash of the recipient's address became an HMAC, because a plain SHA-256 of an email address can be reversed by guessing: hash a list of likely addresses and look for matches.

It worked, and on November 5 I removed it.

## Why the codes went

The codes failed on volume, not on security. Mailingest's target is 8,000 emails a second at peak. One stored code per copy at that rate is 691 million rows a day (8,000 × 86,400), each with its indexes, its WAL and its share of autovacuum. And a code per recipient meant a newsletter to 10,000 people was 10,000 different messages, each signed with DKIM separately, when it could have been one message signed once.

The replacement design starts from a rule written at the top of its doc: Postgres stores data per batch, never per email. Whatever grows with every message lives in object storage.

## A reference and a seal

What the footer carries now is a reference, the message's public id, and a notice that says what was done to the message:

> **TRACEABLE, SECURE EMAIL**
> Signed by ACME (DKIM) and sealed as it was sent by independent timestamping authorities: it can be proven that it existed on this date and that its content has not been altered.
> Reference: em_034nirriFQbsOzF6ig9MFf. Check it at https://verificar.acme.es.

The reference isn't secret, and doesn't need to be. It's a lookup key. What makes it worth anything is what happens to the message as it leaves.

When delivery hands a copy to the outgoing server, it takes a SHA-256 of the copy, after DKIM signing, and publishes that hash to NATS. That's all the mail path does: no network call to an authority, no Postgres write. A collector on each replica gathers the hashes in memory and closes a batch after 60 seconds or 200,000 hashes, whichever comes first.

```
  delivery ──▶ SHA-256 of the copy ──▶ NATS attestation.leaves
                                               │
                                               ▼
                                ┌──────────────────────────────┐
                                │ collector, per replica       │
                                │ 60 s or 200,000 hashes       │
                                │ sorted, then a Merkle tree   │
                                └──────────────┬───────────────┘
                                               │
             ┌─────────────────────────────────┼────────────────────────┐
             ▼                                 ▼                        ▼
  R2: leaves + index               Postgres: 1 row per batch    authorities: the root
  (32 B per hash, bloom filter)    + 1 stamp per authority      (one request each)
```

*The mail path only hashes and publishes; one batch a minute becomes one Merkle tree, one Postgres row and one request per authority.*

The tree follows [RFC 6962](https://www.rfc-editor.org/rfc/rfc6962.html), the one behind Certificate Transparency: a leaf is `SHA-256(0x00 ‖ hash)` and a node is `SHA-256(0x01 ‖ left ‖ right)`. The different prefixes stop anyone from presenting an inner node as if it were a message. Only the root leaves the building. Three authorities stamp it: [Sectigo](https://www.sectigo.com) and [FreeTSA](https://freetsa.org/index_en.php) return [RFC 3161](https://www.rfc-editor.org/rfc/rfc3161.html) timestamp tokens, and [OpenTimestamps](https://opentimestamps.org) anchors it in Bitcoin. Any one of them is enough to prove the date.

A minute of mail, however many messages that is, costs one row in Postgres and three requests. Proving a single message means showing its hash, the few sibling hashes on the path up to the root, and the authority's signature on that root.

## The relay changed my message

The first version hashed the exact bytes that left. Then I sent sealed mail through Amazon SES and Cloudflare, which is how most external mail leaves Mailingest, and the seals stopped matching what recipients had received.

Both relays rewrite the message after the hash is taken. Cloudflare replaces the Message-ID. SES replaces the Message-ID and the Date, rewrites the Return-Path and adds its own DKIM signatures. The receiving servers stack trace headers on top, and a mail client may save the file with bare line feeds instead of CRLF. None of that changes what the message says, and all of it changes the bytes.

So since October 29 the hash is taken over a content form, built the way DKIM builds what it signs. Thirteen header fields that carry content, in a fixed order, each canonicalised like DKIM's [relaxed mode](https://www.rfc-editor.org/rfc/rfc6376.html#section-3.4.2) so that refolding a line changes nothing; an empty line; then the body byte for byte, as DKIM's simple mode does, so a single changed character shows:

```rust:crates/core/src/sealed_form.rs /SEALED_HEADERS/
pub fn of(raw: &[u8]) -> SealedForm {
    let message = crlf(raw);
    let (head, body) = split(&message);
    let fields = fields(head);
    let mut bytes = Vec::with_capacity(body.len() + 512);
    for name in SEALED_HEADERS {
        for (field, value) in &fields {
            if field.eq_ignore_ascii_case(name.as_bytes()) {
                bytes.extend_from_slice(name.as_bytes());
                bytes.push(b':');
                bytes.extend_from_slice(&relaxed(value));
                bytes.extend_from_slice(b"\r\n");
            }
        }
    }
    bytes.extend_from_slice(b"\r\n");
    let mut end = body.len();
    while end >= 2 && &body[end - 2..end] == b"\r\n" {
        end -= 2;
    }
    bytes.extend_from_slice(&body[..end]);
    bytes.extend_from_slice(b"\r\n");
```

The thirteen are From, Sender, Reply-To, To, Cc, Subject, In-Reply-To, References, MIME-Version and the four Content headers. It's an allow-list, so Message-ID, Date, Received, every DKIM and ARC header, Authentication-Results and anything starting with `X-` are outside it. The test that pins it down takes a real message and the copy SES delivered:

```rust:crates/core/src/sealed_form.rs
fn a_copy_relayed_by_ses_has_the_content_that_was_sealed() {
    // New Message-ID and Date, Return-Path, SES's DKIM signatures, the
    // Subject refolded, Gmail's trace headers, bare line feeds.
    assert_eq!(of(SES).sha256(), of(SENT).sha256());
    assert_ne!(sha256(SealFormat::Exact, SES), sha256(SealFormat::Exact, SENT));
}
```

The cost is written in the module's own comment: a change only to the Date, the Message-ID or a transport header goes unnoticed, because those are exactly the fields a relay is allowed to touch. The original Message-ID and Date are kept next to the hash as data, so the verification page can still show them. Each leaf records which form it was sealed in, so the seals made in exact bytes before October 29 still verify the old way.

## What a reference proves, and what a file proves

The verification page takes two kinds of input, and they prove different things.

```
  reference em_...  ──▶  batch whose id range holds it ──▶  bloom filter ──▶  one block read
                         who sent it, when, to whom (masked), subject if allowed

  .eml file         ──▶  content form ──▶ SHA-256 ──▶  same hash as the sealed leaf?
                         yes: "authentic and unchanged", with a proof to download
                         no:  "this email has been changed"
```

*A typed reference tells you who sent a message and when; only the message file can prove its content is the one that was sealed.*

A reference alone answers "Yes, this email is from ACME" and lists the From, the subject, the date and a masked To, with one instruction: "Make sure these details match the email you have. If something doesn't match, it isn't the same email." That catches the lazy scam, a real reference pasted into a fake message. It can't catch a real message whose body someone edited, because the reference is the same.

For that you upload the message itself, which Gmail calls "Download message" and Outlook and Apple Mail call "Save as". The page computes the content form, hashes it and compares. If it matches, you get "This email is authentic and unchanged" and a button to download the proof. If the file names a sealed message but the hash differs: "This email has been changed".

The proof doesn't need Mailingest. It's a tar file with the sealed content, the Merkle path, the RFC 3161 tokens with the authorities' certificates, the OpenTimestamps file, and the content-form procedure rewritten in about a page of standard-library Python (a test keeps it byte-for-byte equal to the Rust). Anyone can check it with `openssl ts -verify` and `ots verify` years after Mailingest is gone.

## The page counts its own visitors

A verification page is also a tool for whoever has a copy of the email, so it watches how it's used. Each check is counted in Redis, and the networks it came from go into a HyperLogLog. When three or more different networks have checked the same message, the page adds: "Careful: this email has been checked 3 times from different places. If that was not you, someone else may have a copy of this email."

Unknown references count too. A domain whose own page sees 50 references it doesn't recognise in an hour gets an alert, because that's what a phishing campaign using its name looks like from the inside. Checking a reference never uses it up: if a check consumed the reference, a scammer could burn other people's.

And next to the form, in both the domain's page and the platform's, the same promise the bank makes, with one addition: "ACME will never ask you for passwords, codes or bank details by email. Neither will this page." The page asks for a reference or a file and nothing else, so there is nothing a fake copy of it could collect that the real one ever asked for.

## Linking it anyway

One decision went back and forth, and it's still uncomfortable. The design said the notice must never link to the page. A phisher who copies the footer would swap the link for their own page, and a reader trained to click "verify" would land on it. So the address was plain text, to be typed by hand.

Then Gmail and other clients turned the plain text into a link on their own, as `http://`. The choice was no longer link or no link; it was our https link or the client's http one. Since this morning the notice carries an explicit `https://` link. The page still tells people to type the address, and the domain can host it on its own name (a CNAME to Mailingest, used only once the DNS is verified) so the address is one the reader already trusts. But the footer is now a link a phisher can imitate, and the only defence left is that the real page never asks for anything.

Strip it back and the trade is this. A footer can't prove anything by what it says, because anyone can say it. What it can do is point at something outside the email: a hash that an independent authority signed at a known time, which no one, Mailingest included, can change afterwards. The reference tells you where to look. The proof is the file you already have.
