Why ODAC Rejects Spoofed Mail Before Disk
Self-hosting your own email used to mean choosing between two bad options. Either you bolted on a sprawling stack of third-party daemons that ate more RAM than your apps, or you accepted every inbound SMTP message at face value and hoped nobody noticed they could spoof ceo@yourdomain over a raw TCP socket.
That shortcut breaks down the moment a real domain goes live. Until recently, ODAC's built-in mail server accepted unauthenticated inbound mail for local recipients without verifying sender authentication or rejecting forged local addresses, and it refused null-sender bounces (MAIL FROM:<>) outright. That kept bad mail flowing into inboxes while silently dropping legitimate delivery status notifications.
So we built native inbound screening directly into the ODAC mail server (internal/mail/spam, wired into internal/mail/smtp/backend.go). Every unauthenticated message now passes through SPF, DKIM, DMARC, HELO, and local anti-spoofing checks during the SMTP DATA transaction, before a single byte is written to disk.
Screen at the Door, Never Bounce Back
A mail filter that runs after a message hits disk is already too late. Once you accept an SMTP 250 OK and later decide a message was forged, you only have two ugly choices: clutter the user's storage with junk or generate a bounce email to a forged return address (creating backscatter spam).
ODAC screens inbound mail inline inside Session.Data before calling storeRaw or expanding Outlook winmail.dat attachments. That architectural choice gives operators two immediate guarantees:
- Zero disk footprint on refused mail: Messages that fail policy receive an SMTP
550 5.7.1reply during the transaction. Zero mailbox rows and zero content-addressed blobs ever touch the filesystem. - Zero backscatter: Because ODAC refuses the message before acknowledging
DATA, the sending MTA (not ODAC) is responsible for reporting the error to its sender. - Clean boundaries for internal traffic: Authenticated SMTP sessions bypass screening completely. Messages sent via the ODAC API (
mail.send) to local accounts commit straight into the recipient's mailbox transaction rather than looping through MX onto port 25 unauthenticated.
At the same time, ODAC enforces screening on both inbound port 25 (STARTTLS) and port 465 (implicit TLS) whenever a session has no login, because port 465 accepts unauthenticated local delivery too. And unauthenticated sessions now accept the null reverse path (MAIL FROM:<>) as RFC 5321 requires, checking SPF against the HELO domain (postmaster@<helo>) per RFC 7208 so legitimate bounces arrive safely instead of disappearing.

Inside the Multi-Layer Screening Pipeline
Every unauthenticated message enters Filter.Check with a strict 15-second context deadline and a panic-recovery boundary. Rather than trusting any single signal, ODAC combines connection hygiene, cryptographic authentication, and structural header validation:
- HELO validation: ODAC inspects how the remote MTA introduces itself. Bare IP addresses (
HELO_BARE_IP, +1.0), non-FQDN strings without a dot (HELO_NOT_FQDN, +1.0), and external servers claiming one of your own domains or hostnames (HELO_FORGED_LOCAL, +3.0) all raise the spam score. Bracketed address literals remain legal per RFC 5321. - SPF verification: Evaluates the
MAIL FROMdomain (or HELO domain for null senders) against the connecting IP. Failures addSPF_FAIL(+3.5),SPF_SOFTFAIL(+1.5), orSPF_PERMERROR(+1.0). - DKIM verification: Verifies up to 5 DKIM signatures (
maxDKIMSignatures = 5) per message. If no signature passes and at least one fails, ODAC scoresDKIM_INVALID(+1.5). - DMARC evaluation: Evaluates RFC 7489 alignment (honoring
sp=subdomain policies andpct=sampling) for every author domain. When all author domains pass, ODAC awardsDMARC_PASS(-1.0) once per message so an attacker cannot farm negative scores by listing multiple domains they control. - No-auth penalty: Messages that pass neither SPF nor DKIM pick up
NO_AUTH(+1.5).
When a domain's DMARC policy is p=quarantine, failing messages receive DMARC_QUARANTINE (+3.0) and land in the Junk folder. When a domain publishes p=reject, failing messages hit DMARC_REJECT (+4.0) and are refused at SMTP time with 550 5.7.1.
Catching the Header Tricks That Fool Strict Parsers
Real-world spammers love parser mismatches. Go's standard net/textproto header reader stops parsing the moment it hits a malformed header line, while most email clients keep scanning past the broken line and render whatever From: header appears below it.
If a spam filter used a strict parser and gave up early, a crafted malformed line above a forged From: header would skip DMARC and spoofing checks while the recipient's mail client still displayed the forged sender.
ODAC avoids that trap by reading headers through mimetree.Fields (internal/mail/mimetree/fields.go), the exact same lenient reader that populates ODAC's mailbox display columns. Every From: field is inspected, every @ address inside unparseable From: values is extracted, and multiple safeguards kick in:
- Missing
Date:addsDATE_MISSING(+1.0), missingMessage-ID:addsMSGID_MISSING(+0.5), malformed header blocks addHEADER_MALFORMED(+2.0), and missing or brokenFrom:headers addFROM_MISSING(+3.0) orFROM_INVALID(+2.0). - Multiple
From:headers or multiple addresses in a singleFrom:triggerFROM_MULTIPLE(+3.0), and every single address is checked independently. - When multiple author domains appear, ODAC applies the strictest failing DMARC policy across all of them.
- Any message naming more than 8
From:addresses (maxAuthors = 8) triggersFROM_TOO_MANY(+5.0) and is rejected outright with550 5.7.1.

Two Rules That Stop Local Impersonation Cold
External DMARC policies only protect domains that actually publish _dmarc DNS records. Self-hosted servers often manage domains whose DNS lives elsewhere, or domains without strict DMARC policies yet, making them prime targets for internal phishing.
ODAC closes that gap with two dedicated local rules that run unconditionally on unauthenticated inbound sessions:
- Forged local accounts (
LOCAL_ACCOUNT_FORGED, +10.0): Every mailbox account on an ODAC server sends outbound mail through an authenticated SMTP session (ormail.send). If an external, unauthenticated session names one of your local accounts inMAIL FROMor anyFrom:address, ODAC rejects it with550 5.7.1, even if SPF and DKIM appear to pass. - Local domain spoofing (
FROM_LOCAL_SPOOF/MAILFROM_LOCAL_SPOOF, +4.0): If an external session claims any address on one of your configured local domains (or subdomains) without an aligned SPF or DKIM pass for that domain, ODAC rejects it with550 5.7.1. This holds true regardless of what DMARC record the domain publishes, and even if it publishes no DMARC record at all.
Why is this so effective? Because only the domain owner controls the DNS records required to pass SPF or DKIM for that domain. Legitimate third-party transactional services configured by you still get through cleanly, while drive-by spoofers are stopped at the TCP door.
Fail-Safe Reliability: DNS Glitches Never Drop Mail
A spam filter that panics on weird MIME or turns a DNS timeout into a permanent 550 bounce is worse than no filter at all. A single stalled resolver could turn every incoming customer email into a permanent rejection.
ODAC treats every transient failure as "unknown", never as spam evidence:
- DNS timeouts add zero points: If SPF, DKIM, or DMARC hits a temporary DNS error (
TempError), it contributes0.0to the score. - Temporary
451deferral on pending refusals: If a message would be rejected by DMARCp=rejector local domain spoofing, AND an aligned SPF or DKIM lookup hit a temporary DNS failure (evaluation.pending), ODAC replies with451 4.7.0instead of550. The sending MTA keeps the message in its queue and retries once DNS recovers. - Database lookup safety: If the local account lookup errors out while checking for
LOCAL_ACCOUNT_FORGED, ODAC logs the error and returns451 4.7.0rather than guessing. - Panic isolation:
Filter.Checkwraps evaluation in arecover()guard. If a crafted message ever trips a parser panic, ODAC logs the stack trace and falls back to an unscreenedINBOXverdict, preventing a remotely triggerable crash loop in the mail daemon.
Inspecting Verdict Headers and Rolling Out With ODAC_MAIL_SPAM
Every screened message that reaches INBOX or Junk gets two standard headers prepended at the very top of the raw message: Authentication-Results and X-Spam-Status. Because ODAC prepends its headers above the original payload, mail clients and downstream filters read ODAC's verdict first and ignore any forged Authentication-Results headers an attacker injected lower down.
Authentication-Results: mx.northstar.dev;
spf=pass smtp.mailfrom=news@mailcraft.net;
dkim=pass header.d=mailcraft.net;
dmarc=pass header.from=mailcraft.net
X-Spam-Status: No, score=-1.0 required=5.0 tests=DMARC_PASS
Any score below 5.0 lands in INBOX, while scores of 5.0 or higher (or DMARC p=quarantine failures) move to Junk. The tests= field lists every rule that fired, giving you an instant audit trail whenever an email lands somewhere unexpected.
Operators control how aggressively ODAC acts on those verdicts using the ODAC_MAIL_SPAM environment variable on the ODAC server container:
ODAC_MAIL_SPAM |
Verdict Behaviour | Best For |
|---|---|---|
enforce (default) |
Delivers to INBOX, moves score >= 5.0 or p=quarantine to Junk, rejects spoofs and p=reject with 550 5.7.1 |
Production servers after verifying third-party senders |
junk |
Never rejects with 550; anything enforce would reject goes to Junk instead |
Servers receiving mailing lists or aggressive forwarders |
tag |
Stamps Authentication-Results and X-Spam-Status headers, always delivers to INBOX |
Auditing third-party relays before enforcing |
off |
Skips all screening checks and adds no headers | Dedicated internal relays behind an upstream gateway |

Step-by-Step Operator Rollout
Because ODAC_MAIL_SPAM is configured directly on the ODAC server container environment rather than via dashboard toggles, rolling it out safely takes four quick steps:
- Audit in
tagmode first (optional for complex setups): If your domains receive mail from legacy contact forms, third-party SaaS senders, or mailing-list forwarders, setODAC_MAIL_SPAM=tagon your ODAC server container and restart it. - Inspect delivered headers: Open a few delivered messages from your newsletters, transactional relays, and external forms. Check
Authentication-ResultsandX-Spam-Statusto verify they pass SPF or DKIM for your domain. If you need to verify which local mailboxes exist for your domain, check app.odac.run or runodac mail list -d northstar.devin your terminal. - Fix unauthorized external senders: Any service sending as a no-mailbox address on your domain (such as
noreply@northstar.devorfounder@northstar.dev) must be authorized in your domain's SPF record or configured with a valid DKIM key. Even if your domain has no DMARC DNS record, ODAC will reject unauthorized external mail claiming your domain onceenforceis active. - Switch to
enforceorjunk: Remove the override (sinceenforceis the default) or setODAC_MAIL_SPAM=enforce.
# Step 1: Observe verdicts in headers without rejecting or moving messages
ODAC_MAIL_SPAM=tag
# Step 4: Default production setting (rejects forged senders and DMARC p=reject)
ODAC_MAIL_SPAM=enforce
Keep one important edge case in mind if your team subscribes to mailing lists or external auto-forwarders. When one of your local accounts emails a mailing list and that list resends the message back to other members on your ODAC server with your user's address still in From:, that inbound copy arrives unauthenticated from outside and triggers LOCAL_ACCOUNT_FORGED. If your users rely on mailing lists that behave this way, set ODAC_MAIL_SPAM=junk so those messages land safely in Junk where they can be recovered instead of bouncing with 550 5.7.1.
Zero-config security shouldn't require bolting an extra gigabyte of Perl or Python spam daemons onto your server. By screening inbound SMTP traffic inside the transaction path, honoring DNS uncertainty with 451 deferrals, and enforcing strict local anti-spoofing before writing a single blob, ODAC keeps forged mail out of your storage and your users' inboxes by default.