karti-ai 428040d964 Fix 13 findings from adversarial milestone-1 review
Blockers in the ingest path (all funnel real mail in milestone 2):
- H1: coerce body bytes to valid UTF-8 (ToValidUTF8) — non-UTF-8/mid-rune cuts
  no longer abort the ingest tx and drop the message.
- H2: EnsurePart's recoverable parse error is non-fatal — proceed with the
  guaranteed-usable Part so messy real-world mail is stored, not rejected.
- H3: extractBodies descends into message/rfc822 (Part.Message via
  SetMessageReaderAt) — forwarded/bounce bodies no longer lost.
- H4: GetMessage/GetThread/GetThreadMessages scoped to inbox_id — no cross-inbox
  access; reply no longer a confused deputy.

Hardening:
- M1: /healthz no longer leaks DB error to unauthenticated callers.
- M2: all DB errors funnel through handleErr; malformed UUID -> 404, dup -> 409,
  internal errors no longer echo the driver string.
- M3: index messages(inbox_id, message_id_hdr) for thread resolution.
- M4: pods UNIQUE(name) + ON CONFLICT (name) — no duplicate default pods.
- L1: skip empty-User/Host addresses (no literal "@").
- L2: skip attachment-disposition parts when picking the body.
- L3: case-insensitive, trimmed 'Re:' detection.

Verified e2e vs Postgres 16: latin1 body stored valid UTF-8; rfc822-only body
extracted; cross-inbox 404; malformed UUID 404; dup 409; threading regression OK.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 13:22:35 -07:00

OpenMail

An agent-native, self-hosted mail server. One Go binary that gives an AI agent its own real email address — receive, parse, thread, search, and send actual SMTP mail on a box you control — behind a clean REST API and an MCP server.

Think "AgentMail, but self-hosted and MIT-licensed." OpenMail embeds the battle-tested mail internals of Mox (also MIT) for the hard, correctness-critical plumbing — DKIM, SPF/DMARC, DANE + MTA-STS secure delivery, real-world MIME parsing, spam filtering — and layers a native, agent-shaped data model (Postgres + object storage) and API on top.

Mail I/O is pluggable: start in minutes against a relay (SES/Postmark/Resend) or your existing mailbox (IMAP/SMTP), and graduate to a fully self-hosted, in-process SMTP engine when you want to own the whole stack. The in-process engine is the part nobody else ships — the only comparable project, agenticmail, runs a Stalwart (AGPL) mail server in a Docker sidecar; OpenMail is one static binary, fully MIT, no sidecar.

Status: early WIP, private during initial build. Will be released MIT-licensed and public. Designed only from public RFCs and public API surfaces — nothing proprietary.

License: MIT — see LICENSE. Builds on Mox (MIT) and the emersion/go-* mail libraries. See ARCHITECTURE.md for the design of record.

Why

The valuable, hard part of an agent-mailbox product is not the API — it's the mail plumbing: receiving over SMTP/MX, sending with real deliverability (SPF/DKIM/DMARC, DANE/MTA-STS, IP reputation), parsing messy MIME, threading, and storage. Hosted products (AgentMail and similar) solve this well but are closed and run on someone else's infrastructure. OpenMail's bet: you can embed an existing MIT-licensed, production-grade Go mail stack instead of rebuilding it, and spend your effort on the part nobody has done well — the agent-native layer.

What makes it agent-native

  • Persistent inboxes as first-class API resources, provisioned in one call.
  • Structured threads, not raw IMAP — In-Reply-To/References stitched into conversations.
  • extracted_text — reply content with quoted history stripped, so an agent reads the new part.
  • MCP server — an agent (Claude Code, etc.) owns and operates its mailbox directly as tools.
  • Webhooks + WebSocket message.received events — agents react to mail in real time.
  • AgentMail-API-shaped REST where reasonable, so existing tooling points at a self-hosted base URL.

Goals

  • Self-hostable in one docker compose up on a single VPS; scales to a fleet later.
  • Deliverability taken seriously — self-host SMTP send with DKIM + DANE + MTA-STS via Mox's delivery stack, or a relay backend (SES/Postmark/Resend) for inbox placement on day one.
  • Single static Go binary with subcommands; Postgres + S3-compatible object store as the only deps.
  • Genuinely MIT — every embedded dependency is MIT/BSD; no GPL/AGPL anywhere in the tree.

Non-goals (for v1)

  • A hosted multi-tenant SaaS. OpenMail is self-host-first (multi-tenant pods exist, but you run it).
  • A full webmail UI. The product is the API + MCP; humans use their own client.
  • Beating a mature provider's deliverability on day one — self-host IP reputation takes warmup + time; the relay backend exists for exactly that gap.
S
Description
Agent-native, self-hosted mail server in Go. Embeds Mox as a library. MIT.
Readme MIT 73 KiB
Languages
Go 99.3%
Makefile 0.7%