Repository navigation
Architecture
How OwnMail's mail service is built and why. How to use it is in Usage; calendars, contacts, sharing, scheduling and AI access are in Groupware. The mail service was designed and built in an earlier program and moved here unchanged; what OwnMail added around it is the control plane described first.
OwnMail is its own mail server in Go. It does not run an existing mail product (no Postfix, Dovecot, Rspamd, Stalwart, ClamAV, …) next to it. It uses Go libraries where writing a wire format or a well-specified algorithm again would only add risk:
| Library | Used for |
|---|---|
github.com/emersion/go-smtp |
SMTP server (incoming, submission) and client (delivery) |
github.com/emersion/go-imap/v2 (pinned beta) |
IMAP protocol; OwnMail implements the session, storage and updates |
github.com/emersion/go-msgauth |
DKIM signing and verification, DMARC record parsing |
blitiri.com.ar/go/spf |
SPF evaluation |
github.com/emersion/go-message |
reading MIME structure (attachments, import) |
github.com/emersion/go-ical, go-vcard, teambition/rrule-go
|
parsing calendars and contacts (see Groupware) |
github.com/modelcontextprotocol/go-sdk |
the MCP endpoint per mailbox |
golang.org/x/crypto/acme/autocert, golang.org/x/net/publicsuffix
|
the mail server's certificate; organisational domain for DMARC |
github.com/ownlabs-dev/ablage, modernc.org/sqlite
|
the databases |
github.com/ownlabs-dev/panzerschrank |
sealing secrets in the database |
github.com/ownlabs-dev/sesam |
sign-in in the browser: the administrators' passwords, sessions and attempt limits, and the sessions of the mailbox area |
Everything that decides what happens to mail (who may receive and send, forwarding, queueing, retries, bounces, filtering, limits) is OwnMail's own code.
ownmail serve runs one process with two parts:
internet reverse proxy (HTTPS)
25 / 465 / 587 / 993 / 4190 │
│ ▼
▼ -listen (:8080, plain HTTP)
mail service (internal/mail/server) │ /api/... administration API
<data>/mail/ index, messages, │ /account/api/, /dav, /mcp, /oauth/...
calendars, queue │ mail service's web handler
▲ │ /.well-known/acme-challenge/...
│ <data>/run/admin.sock │ autoconfig, autodiscover
│ │ /admin/ administration (web)
│ │ / mailbox users' page (web)
control plane (internal/control) ◄─────────────┘
<data>/ownmail.db admins, sessions, domains, mailboxes,
forwarding, DKIM keys (sealed), settings
<data>/secret.key key that seals secrets in the database
<data>/tls/ ACME account and certificates
/admin/ is the administration (talking to /api/), everything else the
page for the people who use a mailbox (talking to /account/api/); both
are single-page apps embedded with the webui build tag
(internal/webui).
-
The control plane (
internal/control) keeps the desired state in<data>/ownmail.dband is the single place where operations and permission checks live. The HTTP API (internal/api) only authenticates and translates. An administrator manages the whole server or only some domains; for the latter everything else answers "not found" (see Usage). Mailbox owners never act through/api/; they use the mail service's own account API (see Groupware). -
The mail service (
internal/mail/server) owns all mail data and speaks SMTP, IMAP and ManageSieve. It gets one complete configuration pushed over its admin socket<data>/run/admin.sock(internal/mail/config), never single changes. It keeps the last configuration it was given and starts with it. -
The web handler of the mail service (
internal/mail/web) serves the mailbox's account API, calendars and contacts (/dav), the MCP endpoint (/mcp) and its authorisation server (/oauth/...).ownmail serveroutes those paths to it on the same listener as the administration API (cmd/ownmail/http.go).
This split comes from the earlier program, where the mail service was a
separate system service with its own user and data directory, driven by a panel
over the same admin socket. OwnMail kept the boundary in the code (the
control plane only talks to the mail service through internal/mail/config)
but runs both in one process under one user, so there is one thing to
deploy. How to run it is in Docker, systemd
and Coolify.
| Part | Role |
|---|---|
internal/mail/config |
The configuration that is pushed, with validation used on both sides; the admin socket's client. |
internal/passwd |
argon2id hashing and the password rules. |
internal/mail/server |
Admin socket, listeners, reloads, graceful shutdown. |
internal/mail/storage |
Mailboxes, folders, messages: SQLite index plus one file per message. |
internal/mail/smtpd |
Port 25 (incoming). |
internal/mail/submission |
Ports 587 and 465 (mail programs sending), and the sending pipeline that calendars and AI programs use too. |
internal/mail/imapd |
IMAP on 993 (implicit TLS only). |
internal/mail/queue |
Outbound queue: delivery, retries, bounces. |
internal/mail/auth |
SPF, DKIM, DMARC verdicts; SRS; DKIM signing. |
internal/mail/filter |
Blocklists, greylisting, content score, attachment rules, Junk. |
internal/mail/deliver, sieve, rules, managesieve
|
Local delivery with filters and out-of-office. |
internal/mail/transfer |
Import and export. |
internal/mail/dav, davobj, sched
|
Calendars and contacts (see Groupware). |
internal/mail/account, oauth, mcpd, client
|
The mailbox's account API and AI access. |
internal/control |
Operations and all permission checks; builds the configuration; DNS records; health. |
internal/api, web/
|
Front doors only. |
<data>/run/admin.sock, in a directory of mode 0700: whoever can reach it
controls the mail service. Endpoints:
| Endpoint | Purpose |
|---|---|
POST /load |
Replace the configuration. Refused if invalid, or if a storage_id is already bound to another address. |
GET /status |
Configuration hash, listeners, certificate expiry, queue size, free disk space and the minimum it needs to accept mail, per-mailbox usage and block state, the mailbox kinds it knows. |
GET /traffic |
Hourly mail counts of the last 8 days (received, junk, turned away, greylisted, sent, bounced, submitted), kept in mail.db as numbers only. |
GET /events?after=<id> |
Events since a cursor: mailbox blocked, sign-in failures from many addresses, delivery problems, changes a mailbox made itself, imports. |
POST /mailboxes/{storage_id}/unblock |
Lift a sending block. |
DELETE /mailboxes/{storage_id} |
Delete a mailbox's data. |
POST /checks/outbound |
Try a connection to an outside port 25 (deliverability check). |
POST /checks/relay |
Connect and sign in to a relay as sending would (the settings' test); sends nothing. |
POST /send |
Send a message the control plane wrote itself (the mails to administrators), from an address in a mail domain or at the mail host's name; the service signs it for a mail domain and delivers or queues it. |
…/imports, …/uploads, …/export
|
Import and export (see Import and export). |
Unix socket paths are limited to about 100 characters, so keep -data
short.
OwnMail's database <data>/ownmail.db (ablage repositories,
internal/store/repos.go; ablage only adds tables, fields and indexes,
and there are no joins): administrators (their passwords, sessions and
failed sign-in counts in sesam's
auth_* tables of the same database), access tokens, mail domains,
DKIM keys (sealed with <data>/secret.key), mailboxes (random 128-bit
storage_id, never reused, password hash, quota, send limits, kind,
display name, app password records), forwarding addresses (* is the
catch-all), organisations, grants, booking rules, the activity log and the
settings (mail_host, server addresses, certificate e-mail, postmaster
address, spam checks).
The mail service's data <data>/mail: mail.db (the index, kept with
ablage repositories, SQLite WAL,
one writer, synchronous=FULL), messages/<storage_id>/…,
dav/<storage_id>/<collection>/… (calendars and contacts), the queue,
import spools, and the SRS key (32 random bytes, created on first start).
Data is keyed by storage_id, so a reused row id or an older database can
never expose another mailbox's mail. Data of a mailbox missing from the
configuration is kept and reported, never deleted by a configuration load.
Block state lives in the mail service (mail.db), not in the pushed
configuration, so a full push can never undo a block. The web interface
shows what /status reports and unblocks through the admin socket.
Durability: before answering 250, the message file and its directory
are fsynced and the index is committed. The same for the queue. At start
the service reconciles index and files (rows without a file are dropped,
files without a row are indexed). A restored index is older than the
clients' caches: when the start-up check finds a difference, or the marker
file restored exists, the service changes UIDVALIDITY of every folder,
and calendars and contacts get a new sync epoch.
Names kept from an earlier version: sealed values, HMAC labels, sync
tokens and similar strings are part of stored data and client caches, so
they keep their old names; never rename them (the list is in
AGENTS.md). The names people
see carry OwnMail's name: the mail headers X-Ownmail-Score and
X-Ownmail-Loop, the generated Sieve script ownmail and the server's own
calendar values X-OWNMAIL-*. Their earlier names are still read where
they were stored, and the script is renamed when the mail service starts.
Names that are not stored carry OwnMail's name too: the account API's X-Ownmail-Request header
(the same as the administration's) and the mailbox cookie
__Host-ownmail_mailbox.
The control plane builds the configuration from its database and pushes it
after every change and in a background loop (-sync-every, default 30
seconds), but only when its hash differs from what /status reports. A
saved change whose push fails answers "saved, but the mail server could not
be updated yet"; the loop retries. Nothing is pushed until the mail
server's certificate was loaded once, so a restart never pushes a
configuration without it. The same loop reads /events and writes them to
the activity log. Before every push, any domain, mailbox or forwarding
address the mail service would refuse is left out or cut down and logged,
so one bad entry never stops mail for everyone.
mail_host (e.g. mail.example.com, -hostname or the setting) is the
name of the server for mail: MX target, the name in SMTP greetings, what
mail programs connect to, and the name the web interface is reached under.
It cannot itself be a mail domain.
The certificate (-tls):
-
acme(default): from Let's Encrypt with the HTTP-01 challenge, answered on-listen(/.well-known/acme-challenge/…formail_hostonly). The reverse proxy in front must pass port 80's challenges formail_hoston to OwnMail. Both an ECDSA and an RSA certificate are obtained (old servers without ECDSA); the service presents them whatever the SNI. Only the HTTP-01 challenge is used: port 443 belongs to the reverse proxy, so the TLS-ALPN challenge could never succeed and would only cost a failed validation at the CA. Failures back off, well inside the CA's limits. -
internal: a self-signed certificate (tests, private setups). -
files:-tls-certand-tls-key, read again when they change (for a certificate the reverse proxy already has, as on Coolify).
Certificates and the ACME account are kept in <data>/tls. The control
plane pushes them in the configuration and pushes again after a renewal.
The mail service opens its mail ports only once it has mail_host, a
certificate and at least one domain.
A mail domain is active only once its MX record, checked at the
authoritative nameservers, points to mail_host. Only active domains are
in the pushed configuration: the service receives for them, delivers to
them locally and lets their mailboxes send. This stops someone from adding
a domain they do not really own (say gmail.com) and catching mail other
mailboxes of this server send there. Inactive domains are looked at every
5 minutes, and on request at most every 5 seconds. Once active, a domain
stays active, even if its MX record changes later (a DNS hiccup must not
stop mail). An administrator can make a domain active without the check
(POST /api/mail/domains/{domain}/activate) for setups the check cannot
see: a gateway in front, split DNS, tests.
Password hashes and DKIM keys are never returned. An administrator can read any mailbox by setting its password; Usage says so.
- STARTTLS offered; plain allowed (server-to-server). No AUTH on port 25.
- Own listener wrapper (
internal/mail/smtpd/listener.go, also used by submission, IMAP and ManageSieve): connections per client and in total, where a client is one IPv4 address or one IPv6 /64 (one network should not take every slot by using many addresses). 5 minutes idle per read; after connecting and after each message a client has 5 minutes to start the next one (MAIL), and a connection lasts at most an hour. Sending a byte now and then extends neither, so a slow client cannot hold its slot for ever; a 50 MB message fits in the hour at about 120 kbit/s. The same limits apply to submission on 587 and 465. Message size limit (50 MB); at most 100 recipients. -
RCPT TOis accepted only for a mailbox, a forwarding address or the catch-all of an active domain,postmaster@/abuse@of every domain and ofmail_host, andSRS0=addresses whose signature checks out and are at most 21 days old (bounces of forwarded mail; only with the null sender). Everything else is refused at once (no backscatter). The null sender<>is accepted. -
postmaster@/abuse@go to the forwarding address of that name if one exists, otherwise to the domain's oldest mailbox. With no mailbox, and formail_host, they go to the postmaster address setting. An outside postmaster address is forwarded to through the queue like a forwarding address. Without a postmaster address, or when it is an address of a domain here that does not exist, they are refused with a temporary error and Server status warns. - Over quota or low disk (below 1 GB free):
452, temporary. - Filtering, see Filtering.
- Settings for programs: server
mail_host, IMAP 993 (TLS), SMTP 465 (TLS) or 587 (STARTTLS), user name = full address. - Automatic setup (
internal/control/mailsetup.go,internal/api/mailsetup.go): Thunderbird autoconfig atautoconfig.<domain>/mail/config-v1.1.xmland<domain>/.well-known/autoconfig/mail/config-v1.1.xml, Outlook autodiscover ("plain old XML") atautodiscover.<domain>/autodiscover/autodiscover.xml, and an unsigned Apple profile (no password) per mailbox with the mail account and, oncemail_hostis set, CalDAV and CardDAV. The public answers exist only for active mail domains and are the same for every address of a domain. The reverse proxy must passautoconfig.<domain>andautodiscover.<domain>on to OwnMail, with certificates for them (clients fetch them over HTTPS). The shipped Caddy configuration gets those on demand and asksGET /api/mail/proxy-certificate?domain=<name>first (Service.ProxyCertificateAllowed: only those two names of active domains), so no certificate is requested for other names pointed at the server; on Coolify the names are added to the service's domains. - A domain's own name for mail programs (
internal/control/clienthost.go, #29): optional, a name below the domain, as CNAME tomail_hostor A/AAAA with the server's addresses. OwnMail gets a certificate for it like formail_host(refreshOwnCerts, same ACME account and HTTP-01 through the proxy, own back-off) and pushes it asother_certificates; the mail service presents it when the SNI asks for that name, elsemail_host's. Setup answers, the Apple profile, the mailbox's own area (pushed asDomain.client_host) and the SRV records use it only while its certificate is valid. MX, calendars and contacts stay onmail_host. - IMAP (implicit TLS on 993 only, RFC 8314):
INBOX,Sent,Drafts,Junk,Trash,Archivewith special-use flags; IDLE, MOVE, UIDPLUS. Folders of mailboxes shared with the signed-in mailbox appear underShared/<address>/…(see Groupware). LITERAL+ is not offered, so an oversized APPEND is refused before the client sends it. A client has 30 s for the TLS handshake and 2 minutes from connecting to sign in; commands do not extend that, so connections that never sign in cannot hold the slots of others. Quota is enforced on delivery and APPEND (NO [OVERQUOTA]); the IMAP QUOTA command is not offered. - Submission on 587 (STARTTLS required before AUTH) and 465 (TLS); AUTH PLAIN and LOGIN.
- Sign-in: the IP throttle runs before any hashing; failures are limited per (IP, address) and per IP, never per address alone (that would let anyone lock a person out); IPv6 counts per /48. When the table of IPs is full, sign-ins from new IPs are refused until old entries expire (never let through uncounted). When only the table of (IP, address) pairs is full, a new pair is not recorded and the per-IP limit alone counts, so filling it cannot lock every mailbox out. A successful sign-in is cached in memory for 15 minutes under an HMAC of address, password and hash, so mail programs that open many connections do not cost an argon2id hash each. Unknown addresses take as long as wrong passwords.
- App passwords (
op_<id>_<secret>) are kept only as an HMAC-SHA-256 bound to the mailbox and the id; see Groupware. - JMAP, POP3, IMAP on 143: not offered.
Forwarding addresses deliver to mailboxes and/or outside addresses (at most
50); * is the catch-all. Expansion stops at depth 10 and removes
duplicates.
- Port 25 accepts addresses that only forward outside. The outside targets of all recipients in one domain become one queued message; local mailboxes get their copy as usual.
-
Envelope sender: the null sender stays null; a sender in one of our
domains (or
mail_host) is kept; everyone else getsSRS0=<hash>=<tt>=<domain>=<local>@<forwarding domain>.ttis the day in two base32 characters as in the common SRS scheme; the hash is the first 40 bits of HMAC-SHA256 overtt=domain=local(lowercase), in base32, compared without case. SRS addresses are accepted for 21 days; bounces to them are routed back to the original sender. -
The message keeps its original
Fromand body; only header fields are prepended (Received,Authentication-Results,X-Ownmail-Score), so the original DKIM signature still verifies. -
Not forwarded: mail judged Junk (score or DMARC
quarantine); the local copies go to Junk and an eventdelivery.not-forwardednames the address and targets. -
Limits: forwarded mail counts once per message against the
forwarding domain's hourly limit, on a counter of its own for mail
that outside mail makes the server send (forwards, delivery reports
passed on, redirects, out-of-office replies), so it never uses up what
the domain's mailboxes may send themselves. When it is reached, the forward is
dropped with an event if the message also reached a local mailbox, and
refused with
451 4.7.1if it had nowhere else to go. - Bounces of forwards: when the outside server refuses a forwarded message for good, the queue sends a delivery status notification to the original sender decoded from the SRS address.
- Submission: outside targets of a local forwarding address go into the queue with the rest of the message; the sender is the signed-in mailbox, so there is no SRS.
- Distribution groups: a forwarding address may accept mail only from its members or its organisation; see Groupware.
- A mailbox may send as its own address or a forwarding address that
delivers to it (the catch-all does not count), and as or on behalf of a
shared mailbox it has the right for, checked for the envelope and the
header
From. The message needs exactly oneFromfield; several addresses in it need aSenderwith one address, which the mailbox must also be allowed to send as. A header section over 1 MB is refused. - DKIM signature (RSA 2048) with the domain's active key.
From,Reply-To,SubjectandSenderare signed once more than the message has them, so a copy added on the way breaks the signature. - Queue on disk, delivery to MX hosts by preference (implicit MX fallback to
A/AAAA, null MX
0 .refuses at once), STARTTLS whenever offered; an unverifiable certificate is accepted (opportunistic TLS); when the TLS handshake itself fails, one retry without TLS. - Retries after 5 min, 15 min, 30 min, 1 h, 2 h, then every 4 h, at most 5 days; then a bounce message (DSN) to the sender. Permanent failures bounce at once. No bounce for bounces.
- Source address: IPv4 unless
-ipv6-outboundis set. Set it only when the IPv6 address has a reverse name namingmail_hostandmail_hosthas a matching AAAA record. - Only public addresses are connected to: mail servers on loopback,
private, link-local, CGNAT, multicast or other special addresses are
skipped, and a domain whose mail servers have only such addresses
bounces at once. Otherwise anyone who can send mail could make the server
open port 25 inside its own network.
-allow-private-mxlifts this for test setups. - On shutdown, an attempt that does not finish within the grace time is cancelled; recipients already done are saved as such, the others are tried again after the next start.
- Outbound MTA-STS and DANE: not built.
OwnMail lists the records to enter and checks them
(internal/control/mailrecords.go). It
never writes DNS; internal/dns only looks things up at the authoritative
nameservers.
| Record | Name | Value | If something else exists |
|---|---|---|---|
| MX | @ |
10 <mail_host>. |
shown as different |
| TXT (SPF) | @ |
v=spf1 mx -all |
the value to enter has mx inserted after v=spf1; several SPF records, +all/?all or more than 10 lookups are reported |
| TXT (DKIM) | <selector>._domainkey |
v=DKIM1; k=rsa; p=… |
shown as different |
| TXT (DMARC) | _dmarc |
v=DMARC1; p=none; adkim=r; aspf=r |
an existing policy is fine |
| SRV (optional) |
_submissions._tcp, _imaps._tcp
|
0 1 465 <mail_host>., 0 1 993 <mail_host>.
|
shown as different |
| CNAME (optional) |
autoconfig, autodiscover
|
<mail_host>. |
judged by where the name resolves (A/AAAA with the server's addresses are fine) |
| SRV, TXT (optional) |
_caldavs._tcp, _carddavs._tcp
|
0 1 443 <mail_host>., path=/dav/
|
listed once mail_host is set |
Optional records only let mail, calendar and contacts programs set themselves up (RFC 6186, RFC 6764, autoconfig, autodiscover); mail is delivered and accepted without them. They do not count as work to do, and the web interface groups them, closed, under "For setting up mail programs" with how many are set up.
The mail server name itself needs records too, listed with every domain:
| Record | Name | Value |
|---|---|---|
| A, AAAA | <mail_host> |
the server's public addresses (-server-ip or the setting) |
| TXT (SPF) | <mail_host> |
v=spf1 a -all (a inserted into an existing one) |
Bounces and delivery reports have the null sender, so receivers check SPF
against the HELO name (mail_host), and mail forwarded with SRS for the
postmaster of mail_host uses it as sender domain. Without this record
those messages fail SPF. Its reverse name (PTR) can only be set by the
hosting provider; the record list says whether it fits.
Names behind Cloudflare's proxy (a record set to "Proxied") answer with
Cloudflare's addresses, and the proxy passes only HTTP(S). OwnMail keeps the
published ranges (internal/dns/cloudflare.go) and, when the mail server
name or autoconfig/autodiscover answer with them, says to set the record
to "DNS only" instead of "points to another server"; this works without the
server's addresses too. The health check mail_host_dns then has
cause: "cloudflare_proxy". An A or AAAA record of a kind the server has no
address of is never optional: it has to be removed.
Each record has a suggested TTL of an hour and a state: ok, missing, different, or unknown when the lookup failed. Long TXT values are split into strings of 255 characters, which some providers need done by hand. MTA-STS policy hosting and TLS-RPT: not built.
In internal/mail/auth and internal/mail/filter (all DNS goes through one
resolver interface, replaced in tests).
- SPF, DKIM, DMARC (alignment with the organisational domain): an
Authentication-Resultsheader on every message. A DMARC failure withp=rejectis refused; withp=quarantineit goes to Junk. - DNS blocklists (default
zen.spamhaus.org): a listing adds to the score; SBL/XBL listings are refused. Answers in127.255.255.0/24mean the query was refused (common through public resolvers) and count as a lookup error, shown under Server status. Optional Spamhaus DQS key. - Greylisting: off by default; when on, only for senders without an SPF pass or without PTR; triplets use the /24 (IPv4) or /64 (IPv6).
- Content score: missing
Message-ID/Date, malformed headers, no PTR, display-name spoofing of the recipient's own domain. - Dangerous attachments (executables, scripts, Office macros) are refused.
- Score at or above the Junk threshold: delivered to
Junk. - Virus scanning: not built; it would need a scanner product this design avoids.
Details:
-
Order on port 25. At
MAIL FROM(once per connection) the client's IPv4 address is looked up in the blocklists (IPv6 addresses are not looked up yet). AtRCPT TO: blocklist refusal, recipient, greylisting. At the end ofDATA: SPF, DKIM, DMARC, attachments, score. Loopback and private client addresses skip blocklists and the PTR check. -
SPF checks
MAIL FROM(the HELO name for the null sender). DKIM verifies at most 5 signatures. DMARC reads_dmarc.<From domain>, else_dmarc.<organisational domain>, whosesp=then applies; it passes when SPF or a DKIM signature passes for an aligned domain. Apctbelow 100 lowers the policy one step for all mail instead of sampling. Lookup errors givetemperrorand never a refusal. -
Answers: DMARC
p=rejectfailure550 5.7.1; aFromfield that cannot be read, more than oneFromfield or more than oneSenderfield550 5.6.0(except from loopback clients, which get themultiple-frompoints instead); Spamhaus SBL/CSS/XBL/DROP listings554 5.7.1for every recipient; dangerous attachment554 5.7.1; greylisted451 4.7.1; header over 1 MB552 5.3.4. -
Headers on delivery (prepended in this order):
Return-Path(local copies only),Received, oneAuthentication-Results: <mail_host>; spf=…; dkim=…; dmarc=…, andX-Ownmail-Score: 3.5 (no-ptr spf-softfail). IncomingAuthentication-Resultsnaming our host and every incoming score header (also under the name earlier versions used) are removed; other servers' results are kept. -
Score points (threshold
mail_junk_score, default 5):no-message-id1,no-date/bad-date1,no-from/bad-from/multiple-from2.5 each,no-ptr1.5 (only when the lookup answered),spoofed-name3 (display name contains@<recipient's domain>while the From domain is not ours),spf-softfail1,spf-fail2.5,dkim-fail1.5 (a failing signature and none passing),listed:<zone>3 per listing that does not refuse,mime-broken1. DMARCquarantinesends to Junk whatever the score. -
Attachments: the MIME structure is read to depth 5 and 500 parts;
file names come from
Content-DispositionandContent-Type. Refused extensions:exe scr com bat cmd pif js jse vbs vbe wsf wsh ps1 msi msp jar lnk hta cpl reg scf iso img vhd vhdx docm dotm xlsm xltm xlam pptm potm ppam ppsm sldm..zipattachments up to 10 MB are looked into one level (names only, nothing unpacked, at most 1000 entries). -
Greylisting: only for clients without reverse DNS or without an SPF
pass. Triplet: network (/24, /64), envelope sender, recipient. The first
attempt and retries within 5 minutes get
451 4.7.1; a retry after 5 minutes (within 24 hours) passes, and the triplet then passes for 30 days after its last message. At most 1000 waiting triplets per network, 5000 triplets per network in all and 200 000 in total. Beyond the last two, the oldest triplets that passed make room (that sender is greylisted once more); only a table of nothing but waiting triplets refuses new ones until they expire after 24 hours. -
Blocklist refusals record the event
blocklist.refusedat most once a day per zone.
The spam settings are pushed in the configuration (filter.blocklists,
at most 10 zones, [] turns them off; filter.junk_score;
filter.greylisting).
Server status (GET /api/mail/health, internal/control/mailhealth.go)
checks, each within a time limit and as "unknown" rather than an error when
a lookup fails: the mail service runs the current configuration,
mail_host resolves to the server's addresses, its SPF record, each
address has a PTR naming mail_host, outgoing port 25 works (the service
tries; the answer is cached), the certificate is valid, every listener is
open, postmaster mail has somewhere to go, no blocklist refused this
server's queries in the last 7 days, and mail programs, calendars and
contacts can connect securely. GET /api/mail/readiness?host= runs only
the checks that need the hosting provider (reverse name, outgoing port 25)
for a name that is not saved yet. Receiving and showing DMARC reports, and
a daily blocklist check: not built.
- Per mailbox: messages per hour and per day (defaults 100 and 500, at most 10 000 and 100 000). One accepted message counts once, whatever the number of recipients; recipients per message are capped separately. The windows slide and are stored, so a restart does not reset them. Per domain: 300 messages per hour. Mail that outside mail makes a mailbox send (redirects, out-of-office replies) has the same limits on counters of its own: it never refuses the mailbox's own mail and never counts towards a block.
- The service blocks sending for a mailbox that hits its hourly limit three times within a day or signs in successfully from more than 10 networks in an hour (IPv6 counted per /64, so phones are not mistaken for attackers); receiving goes on. The block is an event: activity log, a mark in the web interface. Only administrators unblock.
- Free disk below 1 GB: incoming mail, APPEND, COPY and MOVE answer temporary failures.
Moving to OwnMail means bringing old mail along; leaving means taking it out. Both run in the mail service, because only it reads and writes mail data. The control plane starts and cancels jobs, passes files through without buffering and shows progress. Export reads a whole mailbox without its user noticing, so it is recorded in the activity log and limited to one export per mailbox at a time and four in the service.
Sources:
- Another mail account over IMAP: server name, port 993 (TLS) or 143 (STARTTLS, required), user name, password. Works with providers that allow IMAP with a password or an app password. Microsoft 365 and Outlook.com are not supported (they require an OAuth sign-in).
-
A file upload:
.mbox,.eml, or a.zipof those, including OwnMail's own export. Google Takeout must be exported as.zip.
Flow: check first (sign in, list folders with message counts and sizes
against the quota; nothing copied), then choose folders and start, then
progress with what was copied, skipped as already there, or failed (at
most 1000 failures listed). For IMAP the password is sent again with the
start request and lives only in memory for the running job; it is never
written to mail.db, logs, events or errors. After a restart a running
IMAP job becomes interrupted and asks for the password again; a file job
resumes by itself.
Reading the source:
- IMAP stays read-only on the source (
EXAMINE,BODY.PEEK[]). Messages over the message size limit are skipped without downloading. - The other server is untrusted: its answers are read with bounded sizes and counts, and the connection ends when nothing moves for 5 minutes. The host is resolved once, every address must be public, and the service dials that address itself with TLS for the host name; certificates are verified; only ports 993 and 143.
- Flags kept:
\Seen,\Answered,\Flagged,\Draft, and valid keywords (at most 50). - Special-use folders map to ours (
\Sent→ Sent and so on); without attributes, well-known names do too (Sent Items,Gesendet,[Gmail]/Sent Mail, …). Gmail's "All Mail" is copied last into Archive, skipping messages already imported elsewhere. - Google Takeout: labels in
X-Gmail-Labelsbecome folders; mail without a label goes to Archive.
Repeats: every imported message records a hash of its normalised content per folder, and IMAP jobs keep the highest UID copied per remote folder, so running the same import again copies only what is new. This is how a cutover works: import, move the MX record, import again.
Jobs: one import per mailbox at a time, at most two running in the service. Gmail's daily download limit pauses a job instead of failing it. The first failed sign-in ends the check or job; at most 10 checks and starts per mailbox an hour. Imported mail does not count as sending, is not filtered and is not forwarded; the quota and free disk space are checked before every message.
Uploads are chunked and resumable: the client declares name and size
(at most 20 GiB) and sends parts of at most 256 MiB with
PUT …/uploads/{id}?offset=; the service answers the bytes it has.
Zip files are untrusted: at most 100 000 entries and 1000 folders, no
.., absolute paths or backslashes, nested zips not opened.
Export: a .zip with manifest.json and one mboxrd file per folder
(flags as Status:/X-Status:/X-Keywords: lines), plus the mailbox's
calendars and address books. OwnMail's own zip imports back without loss.
Not built: people use mail programs. A webmail would be a separate web app on top of the mail service; see Groupware.
One server, SQLite and files: a few hundred mailboxes.
This wiki is copied from docs/ in the repository; changes go there, in a pull request.