Getting started
Architecture
The crates, the single binary and its roles, PostgreSQL and the blob store, the change sequence, and what scales and how.
On this page
RustPost is one Rust program, rustpost, built from a Cargo workspace of small crates. The webmail and the admin console are static single-page apps (React and MUI) that the server serves; Node.js is only used to build them.
One binary
rustpost serve starts everything the configuration file asks for:
| Role | Default port | Notes |
|---|---|---|
| SMTP | 25 | Always on. Inbound mail from other servers. |
| Submission | 587, 465 | Optional. Mail clients send here, with a login, over TLS only. |
| IMAP | 143, 993 | Optional. Logins only over TLS. |
| ManageSieve | 4190 | Optional. STARTTLS on the same port. |
| HTTPS | 443 | Optional. Webmail, admin console, JMAP for the webmail, CalDAV and CardDAV at /dav/, WKD, autoconfiguration. |
| Queue worker | none | On by default; delivers outbound mail, invitations and rule runs. |
Background jobs also run in the same process: deleting old message traces, syncing antispam settings, purging calendar and contact tombstones, indexing the directory, expiring web sessions and uploads.
The other subcommands manage the store without starting the server: domain add, domain dkim, user add, admin grant and admin revoke. See Installation.
The crates
| Crate | What it does |
|---|---|
rp-core | Shared ids and value types. |
rp-store | The storage interface, with no SQL, and its conformance suite. |
rp-store-postgres | The store on PostgreSQL (sqlx) and its migrations. |
rp-blob | Immutable, content-addressed blobs on the filesystem. |
rp-bus | In-process wake-up notices. |
rp-mail | The single API for changing mail; every protocol goes through it. |
rp-mime | Wrapper around the mail-parser crate. |
rp-mailauth | DKIM signing and SPF, DKIM, DMARC and ARC checks (wraps mail-auth). |
rp-smtp-wire, rp-smtp | SMTP parsing (wraps smtp-proto) and the inbound and submission servers. |
rp-queue | Outbound delivery, retries, delivery reports, smarthosts. |
rp-imap-wire, rp-imap | IMAP parsing (wraps imap-codec) and the IMAP server. |
rp-sieve | A Sieve parser, checker and interpreter of its own. |
rp-managesieve | ManageSieve (RFC 5804). |
rp-identity | Local passwords (Argon2) and SASL. |
rp-antispam | Screening of mail on port 25. |
rp-http | Static files, sessions, CSRF, JMAP transport, DAV, WKD, autoconfiguration. |
rp-jmap | The JMAP subset the webmail speaks. |
rp-admin-api | The REST API of the admin console. |
rp-dav, rp-calendar, rp-ical | CalDAV and CardDAV, calendars, iCalendar. |
rp-contacts, rp-vcard | Contacts, the directory, vCard. |
rp-crypto | OpenPGP and S/MIME public keys, WKD, key lookups. |
rp-net | TCP with TLS (rustls with the aws-lc-rs provider). |
rustpost | The binary: configuration and command line. |
Third-party protocol libraries stay behind the wrapper crates, and cargo deny enforces it. That keeps the dependency on any one library replaceable.
Storage
PostgreSQL holds everything except message bodies: accounts, mailboxes, message metadata, flags, the queue, calendars, contacts, Sieve scripts, public keys, sessions, message traces and settings saved from the console. It is the only database. Migrations run when the server starts, under a database-wide lock, so nodes that start together migrate one at a time.
The blob store holds message bodies and attachments as files under [blobs] path, at <org>/<aa>/<bb>/<sha256>. A blob is written to a temporary file, flushed with fsync, renamed into place, and its directories are flushed too. Only then is the metadata committed, and only then does SMTP answer 250.
Blobs are immutable and never contain local paths in the database, so the store can move to S3 later under the same addresses. S3 support is planned.
The change sequence
Every account has one counter. Each transaction that changes the account first reserves a range of that counter by updating the account row, which also locks it, so the commit order and the sequence order are the same. The sequence feeds IMAP MODSEQ values and the webmail's JMAP state, and a change log records what changed at each step. Calendars, contacts and keys use the same counter.
That is why IMAP and the webmail always agree: they read the same history.
What scales and how
The design rule is that durable state lives only in PostgreSQL and the blob store, never in a node's memory. Today:
- Shared between nodes already: web sessions, the outbound queue (recipients are leased, 15 minutes by default), periodic jobs that must run once (a
job_leaserow picks one node), and the per-row inboxes for invitations, Autocrypt and rule runs. - Per node: rate limits (counted in memory), the admin console's log view, and the wake-up bus. IMAP IDLE also polls every 30 seconds, so a change made on another node shows up within that time.
- Planned: S3 blobs, a cross-node bus, PROXY protocol, and a tested two-node setup.
The plan's stages, all design targets that have not been measured:
| Stage | Backends | Target |
|---|---|---|
| S0 | PostgreSQL and filesystem blobs, one node | about 2,000 mailboxes |
| S1 | PostgreSQL and S3, one active node | about 10,000 mailboxes |
| S2 | 3 to 6 stateless nodes | 10,000 to 50,000 mailboxes |
Security model in one paragraph
TLS 1.2 and 1.3 everywhere passwords travel; logins are refused on plain connections. The webmail uses a __Host- session cookie and a CSRF header check, renders mail in a sandbox with remote content blocked, and does all end-to-end cryptography in the browser. The code forbids unsafe. See Security.