Alpha, active development·Rust·source →

Mailwright

Self-hosted mail and groupware with the functional scope of an enterprise email suite

Why it exists

I built Mailwright because the available options for self-hosted mail were inadequate. The established open-source ecosystem consists of disparate, old, and unintegrated single-purpose systems for transport, delivery, filtering, and groupware. Each system has its own configuration and long-standing performance problems. The small number of modern alternatives are freemium products with constrained open-source editions and viral licenses. Neither approach provides a self-contained replacement for a Google enterprise email account that places mail hosting, groupware, calendaring, contacts, and spam filtering under one administration interface.

I wanted a system that was massively scalable, highly performant, modern, and fully integrated but did not impose those licensing constraints. Mailwright meets these requirements by hosting mail, running groupware, filtering spam with current techniques, and operating as an MTA with an administration interface designed for multi-tenant, multi-domain environments.

What it is

Mailwright is a mail and groupware platform. Its current implementation is a single Rust server process, which is the deliberate MVP form for a system designed to scale out into services on a Kubernetes platform. The transport layer is an SMTP and LMTP MTA that includes a durable queue, DKIM signing, DANE and MTA-STS outbound policy, and DSN generation. It provides mailbox access through IMAP4rev2 (including CONDSTORE, QRESYNC, and IDLE), POP3, and JMAP Core and Mail, with push delivered over WebSocket and EventSource. A Sieve engine provides server-side filtering and can be managed by clients through ManageSieve.

The groupware component is a WebDAV, CalDAV, and CardDAV server with a twenty-privilege ACL model and iTIP/iMIP scheduling, which allows calendar invitations, replies, and free-busy queries to operate between users and across organisations. Spam filtering uses SPF, DKIM, DMARC, and ARC verification together with a Bayes-and-heuristics analysis pipeline that can be tuned for each deployment. Authentication uses a built-in directory with OIDC and OAuth2 bearer support, while ACME automatically issues and renews TLS certificates. An HTTP API and operator CLI provide administration for installations that host many domains and tenants.

How it works

The server runs as one process and uses role-based storage. Data, blobs, full-text search, caching, and pub/sub each use a configurable backend. A single-machine installation can use RocksDB, while deployments that need to scale out can use PostgreSQL, S3, Redis, and NATS. The same binary supports both configurations, and the role boundaries define where the planned division into services will occur.

Telemetry is based on a single typed event model in which each event generates structured logs, metrics, and traces from one emission point across a catalogue of several hundred named events. The configuration system includes an expression language that compiles into per-message conditionals. Routing rules, recipient policy, and spam thresholds use this language, which maintains multi-domain configuration in one location and format.

Architecture

Mail clients IMAP · POP3 · JMAP Calendars & contacts CalDAV · CardDAV Peer mail servers SMTP Operators admin API · CLI MAILWRIGHT · ONE SERVER PROCESS PROTOCOL SURFACE SMTP / LMTP DKIM · DANE · MTA-STS · DSN IMAP4rev2 CONDSTORE · QRESYNC · IDLE JMAP Core + Mail push: WebSocket · EventSource POP3 legacy retrieval Sieve / ManageSieve server-side filtering CalDAV / CardDAV WebDAV · 20-privilege ACLs Admin HTTP API multi-tenant · multi-domain CORE SERVICES Spam analysis SPF/DKIM/DMARC/ARC + Bayes Message queue durable · crash-safe Scheduling iTIP / iMIP · free-busy Directory & auth OIDC · OAuth2 Config engine per-message expressions Typed telemetry logs · metrics · traces ACME automatic TLS STORAGE ROLES Data mail · metadata Blobs message bodies Full-text search index Cache hot state Pub/Sub events · push each role binds to the backend the deployment configures RocksDB embedded, single box PostgreSQL relational S3 object storage Redis cache NATS pub/sub

Message and scheduling flows

The diagrams below trace the two flows that define a mail and groupware server. The first covers an inbound message from the peer connection to the client notification, and the second covers a calendar invitation from the organizer's save to the attendee's reply. The state panels beneath the flows present three associated lifecycles: the read states of the SMTP session, the delivery lifecycle and DSN categories of a queued recipient, and the per-recipient SCHEDULE-STATUS vocabulary specified by RFC 6638.

INBOUND MESSAGE · SEQUENCE Peer MTA SMTP session Spam pipeline Delivery engine Mailbox store Relay queue Event bus Clients EHLO · STARTTLS · AUTH MAIL FROM · RCPT TO classify recipients: local / relay (directory) DATA · BDAT: message body analyze: one shared parse SPF · DKIM · DMARC · ARC, then Bayes · heuristics · rules verdict: stamp X-Spam-*, or 550 reject deliver local recipients Sieve per account: keep · fileinto · redirect append by content hash message-state notification enqueue relay recipients, durable 250 OK, after local delivery commits IMAP IDLE burst · JMAP StateChange push SMTP SESSION · READ STATES (enum Next) Sasl StartTls Command Data Chunk Close AUTH ok / fail STARTTLS TLS up DATA 354 replies written BDAT chunk · LAST QUIT · 421 · auth failures RELAY QUEUE · RECIPIENT LIFECYCLE (enum RecipientStatus) Scheduled no attempt yet Completed terminal · delivered DSN TemporaryFailure retriable · delayed DSN 4.0.0 PermanentFailure terminal · failed DSN 5.0.0 remote accepts: 250 4xx · DNS · TLS · rate limit retry at retry_due, backoff schedule later attempt succeeds 5xx · expiry sweep expired without attempt CALENDAR INVITATION · SEQUENCE Organizer CalDAV write Diff engine iTIP dispatch Local inbox Relay queue Remote attendee PUT event with ATTENDEE list diff snapshots: method · recipients · SEQUENCE commit: SCHEDULE-STATUS 1.0 pending one iTIP message per change internal delivery → 1.2 delivered iMIP (RFC 6047) via submission seam SMTP to attendee's server → 1.1 sent REPLY: attendee PUT or signed RSVP link set one PARTSTAT · same shared write path organizer copy updated, REPLY fanned out SCHEDULE-STATUS · PER RECIPIENT (RFC 6638) 1.0 Pending between write and task 1.2 Delivered internal inbox, known 1.1 Sent iMIP accepted by queue 5.1 Transport failure submission refused 3.7 · 3.8 invalid user · no privilege 5.2 No route no capability local recipient external recipient, queue accepts a transport failure never fails the calendar write: the object commits first, the status records the outcome

Where it is going

The single process is the MVP, while operation at enormous scale remains an explicit goal of the project. The current design work decomposes Mailwright into a multi-service application on Kubernetes. Its protocol surfaces, queue, delivery, filtering, and groupware stack will operate as independently deployable and independently scalable services. The role-based storage architecture supports this design because components that already access data, blobs, search, cache, and pub/sub through separate backends can be divided without re-plumbing their state. The service decomposition remains in design, and the monolithic server remains the supported deployment while that work proceeds. As a result, a current single-box installation carries forward into the scaled-out model.

Why it matters

Organisations seeking to leave hosted email currently must either assemble aging single-purpose services or use the limited open-source edition of a freemium product. Mailwright provides the full set of functions, from the MTA through calendaring and spam filtering to the admin API, in a single system that runs on user-controlled hardware. It is currently in alpha. Transport, IMAP, POP3, and filtering are its most complete areas, while the groupware stack remains under active development. Its intended scope includes everything provided by an enterprise mail account.