Stalwart: the lightweight mail server in a single container
Set up Stalwart Mail Server with Docker Compose: DNS records, setup wizard, first mailbox, spam filter and Sieve – SMTP, IMAP and JMAP in one container.
Table of contents
Your own mail server doesn’t have to consist of two dozen containers. Stalwart packs the complete mail server (SMTP, IMAP, JMAP, spam filter and storage) into a single container written in Rust. That makes it lean, fast and low-maintenance: the modern, lightweight alternative to heavyweights like Mailcow. Which of the two suits you is settled in the direct comparison of Stalwart and Mailcow.
Mail servers stay demanding – no matter how lean
What are we building?
By the end, Stalwart 1.1.1 runs as a single Docker container on your server and provides everything a full-featured mail server needs:
- SMTP: accepting mail from other servers on port 25, sending from your clients over port 465,
- IMAP (993) and the modern JMAP for fast, efficient clients,
- ManageSieve (4190) for server-side filter rules,
- a built-in spam and phishing filter (no separate Rspamd/ClamAV needed),
- integrated storage (RocksDB), so no external database,
- a modern web interface to manage domains, accounts and settings.
The big difference from Mailcow: it’s one process, one container, a few hundred megabytes of image. That significantly reduces RAM demand, attack surface and maintenance effort.
Why is the lean approach worth it? A classic mail server stack consists of a good dozen services (Postfix, Dovecot, Rspamd, a database server, a virus scanner, Redis, a web server), all of which run individually and have to be updated and tuned to each other. Each of them is a potential source of error and a piece of attack surface. Stalwart bundles the same functionality into a single application written in Rust. Rust also brings memory safety out of the box. For software that accepts unfiltered data from the entire internet, that’s a real security argument.
Prerequisites
- A server with Debian 13 and Docker installed, on which the mail ports 25, 465, 993 and 4190 are free. This recipe also takes port 443, because Stalwart fetches its own certificate. It still doesn’t need a server of its own: if your reverse proxy already holds 443, Stalwart moves in next to it; see the box in step 4.
- A domain whose DNS you control yourself, for the mail server’s A record and the MX record.
- Outbound SMTP must be open. Many providers block it against spam. At netcup the default policy “netcup Mail block” (ports 25/465/587) does it. You take it off the server yourself in the SCP, no support ticket needed; see netcup firewall setup. Without an open port 25 you can’t deliver mail to other servers.
- A PTR/reverse-DNS entry for the server IP (in the netcup SCP) that points to your mail hostname.
Stalwart is frugal: at idle the container uses around 180 MB of RAM. While importing large mailboxes it climbs to about 750 MB and only hands the memory back on the next restart. So plan at least 1 GB for Stalwart alone; with a 512 MB memory limit the kernel kills it mid-import. One of the smaller netcup plans is enough to start. How much your setup needs in total is estimated by the server calculator.
VPS 1000 G12.5
4 vCores · 8 GB RAM · 128 GB SSD
from €14.50/month
Stalwart is lean – the VPS 1000 is quite enough to start.
💶 1 month free:
Single use, valid for VPS 1000 G12.5. Redeem in the cart →
💶 €5.95 voucher for new netcup customers: always valid · not for domains or VPS Lite
Step by step
Step 1: Create the DNS records
First set up the DNS entries, as they need time to propagate. YOUR_DOMAIN is your mail domain, YOUR_SERVER_IP the server’s IPv4 address:
mail.YOUR_DOMAIN. A YOUR_SERVER_IP
YOUR_DOMAIN. MX 10 mail.YOUR_DOMAIN.
autoconfig.YOUR_DOMAIN. CNAME mail.YOUR_DOMAIN.
autodiscover.YOUR_DOMAIN. CNAME mail.YOUR_DOMAIN.
mta-sts.YOUR_DOMAIN. CNAME mail.YOUR_DOMAIN.
ua-auto-config.YOUR_DOMAIN. CNAME mail.YOUR_DOMAIN.The MX record refers other mail servers to mail.YOUR_DOMAIN. This hostname is your server’s identity. SPF, DKIM and DMARC are added by the email deliverability tutorial; Stalwart generates the DKIM keys itself during setup.
The four CNAMEs are not optional, even though they look like it: Stalwart requests a single Let’s Encrypt certificate covering all five hostnames at once. If one of them is missing from DNS, the entire certificate order fails, including for mail.YOUR_DOMAIN. As a bonus, those are exactly the names mail programs later use to find their settings automatically (autoconfig/autodiscover). If your DNS provider doesn’t allow CNAMEs at this level, four A records pointing at YOUR_SERVER_IP do the job just as well.
Step 2: Write the compose.yaml
Create a folder and change into it:
mkdir -p /opt/stalwart && cd /opt/stalwartCreate the file compose.yaml:
services:
stalwart:
image: stalwartlabs/stalwart:v1.1.1
container_name: stalwart
restart: unless-stopped
ports:
- "25:25" # SMTP (accepting mail from other servers)
- "465:465" # SMTPS/submission (sending, implicit TLS)
- "993:993" # IMAPS
- "4190:4190" # ManageSieve
- "8080:8080" # web interface & JMAP (initial setup)
- "443:443" # HTTPS (console & JMAP after setup)
volumes:
- stalwart_config:/etc/stalwart
- stalwart_data:/var/lib/stalwart
volumes:
stalwart_config:
stalwart_data:The most important thing: one service and two volumes that together make up the complete server. /etc/stalwart holds nothing but a tiny config.json pointing at the data store. /var/lib/stalwart holds the actual content: settings, accounts, messages and the DKIM keys. Mounting a volume at any other path inside the container has no effect, because the image only ever writes into these two directories. (The /opt/stalwart folder on the host from above is unrelated: it only holds your compose.yaml.)
Stalwart fetches its TLS certificate later itself via Let’s Encrypt; you don’t need a separate reverse proxy for that. Make sure port 443 is free on the host (Stalwart also uses it for the certificate retrieval, see step 4).
Why no port 587 and 143?
587 (submission with STARTTLS) and 143 (IMAP without TLS). Stalwart doesn’t create a listener for those two ports out of the box, so a mapping would point at nothing. By default exactly seven services listen: smtp (25), submissions (465), imaps (993), pop3s (995), sieve (4190), http (8080) and https (443). If you really need 587 or 143, create the listener in the console under Settings → Network → Listeners and add the port mapping.Step 3: Start the container and get the startup password
Start Stalwart:
docker compose up -dOn the very first start, Stalwart runs in bootstrap mode: there’s no configuration yet, and port 8080 is open for the initial setup. In the process it generates a one-time administrator password that you read from the logs:
docker compose logs | grep -A4 "temporary administrator"stalwart | 🔑 Stalwart bootstrap mode - temporary administrator account
stalwart |
stalwart | username: admin
stalwart | password: <ONE-TIME-PASSWORD>Username and password sit two and three lines below the heading, which is why it’s -A4 and not less. As long as setup isn’t finished, every restart generates a new one-time password; if grep shows several blocks, the last one counts. (If you’d rather set a fixed password, you can store a STALWART_RECOVERY_ADMIN=admin:YOUR_PASSWORD under environment: in the compose.yaml.)
Step 4: Log in and run through the setup wizard
Open the web interface in the browser: http://YOUR_SERVER_IP:8080/admin. You land on the login. Log in as user admin with the one-time password from step 3. The input is done in two steps (first username, then password):

After logging in, the setup wizard greets you. In the first step you set the server identity:
- “Server Hostname”:
mail.YOUR_DOMAIN, the FQDN from your A record. - “Default Email Domain”:
YOUR_DOMAIN, your mail domain. - “Automatically Obtain TLS Certificate”: leave enabled; Stalwart fetches the Let’s Encrypt certificate itself. For that, port 443 must be reachable from outside: Stalwart uses the TLS-ALPN-01 challenge over 443 by default, it doesn’t need port 80 for it.
- “Generate Email Signing Keys”: leave enabled; that generates your DKIM keys right away.

Click through the further steps of the wizard:
- Storage: the default RocksDB is an embedded key-value store and perfect for single-server setups, with no external database server needed. Only for large, clustered installations do you reach for PostgreSQL or similar. Leave the fields below it (attachments, search index and the store for short-lived data such as sessions and rate limits) at their defaults.
- Directory: the internal directory manages accounts and passwords directly in Stalwart. Whoever already runs a central LDAP/Active Directory can connect it here instead; for getting started you stay with the internal directory.
- Logging: switch “Log Destination” to
Console. The default Log file writes into a file inside the container that nobody ever gets to see in a Docker setup; after that,docker compose logswould stay empty forever. WithConsoleeverything lands where you expect it. For the “Logging level”,Infois a good compromise in everyday use; on problems you briefly turn up toDebug. - DNS: for the start, manual management is enough. Stalwart shows you the records to create later under the respective domain.
At the end, Stalwart generates your permanent administrator account and shows the address and password a single time. Write both down immediately. The username from now on is the full address admin@YOUR_DOMAIN, no longer the short admin from bootstrap mode.
The wizard’s last message is easy to miss and still decisive: Stalwart has to restart for the freshly written configuration to take effect.
docker compose restartAfter that the bootstrap mode is over and the console additionally answers via HTTPS on port 443. The HTTP listener on 8080 stays in place. That’s handy behind a reverse proxy, but one more reason not to hang it on the internet unprotected.
From now on you sign in only via the hostname over HTTPS: https://mail.YOUR_DOMAIN/admin. The web interface is itself an OAuth client, and its client id is exactly that address. Via http://YOUR_SERVER_IP:8080/admin the login form still loads, but signing in fails with “Unknown client id”, and the same happens with the hostname on port 8080.
Already using a reverse proxy?
Unlike classic mail servers, Stalwart can run its web interface behind an existing Traefik without problems; then simply route the HTTP port 8080 there. The mail ports (25, 465, 993, 4190) must still be directly at the server, because they don’t speak HTTP and can’t be routed through an HTTP proxy.
You still don’t open the setup wizard via the proxy address: in bootstrap mode, Stalwart rejects a sign-in via https://mail.YOUR_DOMAIN with “Client metadata documents are disabled”. Use http://YOUR_SERVER_IP:8080/admin or, if 8080 is only published on 127.0.0.1, an SSH tunnel (ssh -L 8080:127.0.0.1:8080 YOUR_USER@YOUR_SERVER_IP, adding -p YOUR_SSH_PORT if SSH runs on another port) and http://localhost:8080/admin. After the restart it flips around: from then on only https://mail.YOUR_DOMAIN/admin works.
If the proxy already occupies port 443, Stalwart can no longer fetch its certificate itself via TLS-ALPN-01. You still don’t have to install anything by hand: let Traefik obtain the certificate as before and hand it over to Stalwart. A traefik-certs-dumper container writes the certificate and key from acme.json into a shared volume, Stalwart mounts it read-only and reads both as files (Settings → TLS → Certificates, pointing at /data/certs/mail.YOUR_DOMAIN/cert.pem and key.pem). Give the dumper OVERRIDE_UID: 2000 and OVERRIDE_GID: 2000, because Stalwart runs as uid 2000 inside the container and cannot read the key otherwise. Stalwart or Mailcow? walks through it step by step, renewal included; Stalwart then serves the very same Let’s Encrypt certificate on 993 and 465 that Traefik uses for the web interface.
Step 5: Create a domain and first mailbox
Sign in at https://mail.YOUR_DOMAIN/admin as admin@YOUR_DOMAIN. You land right in the management console. Further domains go under Domains → Domains in the left navigation, the mailboxes under Directory → Accounts:

Via “Create user” you create a mailbox: username (the local part before the @), domain and display name. Under Authentication, “Add item” adds a password, a strong one from your password manager. “Create” saves the account, and it can sign in via IMAP/JMAP and SMTP right away:

Step 6: Set it up in a mail program
Enter the new account in your mail program. Stalwart supports autodiscovery, so usually the email address and password are enough. Manually you use:
IMAP: mail.YOUR_DOMAIN, port 993, SSL/TLS
SMTP: mail.YOUR_DOMAIN, port 465, SSL/TLS
User: the full email addressBoth ports use implicit TLS: the connection is encrypted from the very first second. If your mail program stubbornly suggests port 587 with STARTTLS, switch it to 465 by hand; Stalwart doesn’t ship the submission listener on 587 (see step 2).
Besides the tried-and-true IMAP, Stalwart also speaks JMAP, a modern, JSON-based protocol designed for today’s networks. JMAP transfers only real changes instead of re-syncing whole folders, gets by with a single connection and is thus noticeably more sparing with battery and data, especially on the phone. If your mail client supports JMAP (e.g. the Thunderbird family in newer versions), you benefit directly; otherwise you stay with IMAP, which works just the same.
A mail from you to yourself should land in the inbox immediately. That proves that local delivery, IMAP and SMTP are in place. The acid test, though, is sending to the outside and receiving from the outside, and there deliverability decides.
Note
Step 7: Spam filter and Sieve rules
A big advantage of Stalwart: the spam and phishing filter is already built in and active. You don’t have to run and maintain a separate Rspamd container. It rates incoming mails based on numerous features (reputation, SPF/DKIM/DMARC result, content heuristics) and marks or blocks suspicious ones. Its settings live in a separate area of the console: three icons sit at the bottom left, and the middle one (sliders) switches from Management to Settings. There you find Spam Filter with the subsections General, Classifier, Rules, Scores, DNSBL and Lists; this is where you tune how strictly the filter judges.
For your own rules on incoming and outgoing mail, Stalwart supports Sieve, the standardized filter language. With it you sort e.g. newsletters automatically into a folder or forward certain senders. You manage Sieve scripts server-side (via ManageSieve on port 4190) or directly in the web interface, so the rules take effect independent of the mail program, even when your computer is off.
Tip
When things go wrong
The web interface on port 8080 doesn’t respond. The container is still booting or port 8080 is
occupied/blocked. Check docker compose ps, read docker compose logs and make sure the
firewall lets port 8080 (and later 443) through. If the log
output stays completely empty after the setup, the log destination is still set to Log file.
Switch it to Console in the console under Settings → Telemetry → Tracers and restart.
The first sign-in fails with “Client metadata documents are disabled”. You’re opening the setup wizard via HTTPS or your reverse proxy. As long as Stalwart is in bootstrap mode, signing in only works via http://…:8080/admin, directly via the IP or through an SSH tunnel to localhost:8080.
Signing in fails with “Unknown client id”. You’re opening the console via http://…:8080 or the IP address. After the setup, signing in only works at
https://mail.YOUR_DOMAIN/admin, with the hostname from the wizard and over HTTPS.
I missed the bootstrap password. As long as the wizard isn’t finished, a docker compose restart
is enough; Stalwart then logs a new one-time password. More permanently: set a
STALWART_RECOVERY_ADMIN=admin:YOUR_PASSWORD under environment: in the compose.yaml and restart
with docker compose up -d. That gives you a fixed recovery-admin account.
No TLS certificate, the HTTPS address shows a warning. Either Let’s Encrypt can’t reach your
server on port 443 (Stalwart uses the TLS-ALPN-01 challenge over 443), or one of the five hostnames
from step 1 is missing in DNS. The log names the culprit:
ACME authentication error … NXDOMAIN looking up A for autoconfig.YOUR_DOMAIN. Add the missing
records, open port 443 in the firewall; Stalwart retries the certificate request automatically
afterwards.
Mails to the outside stay stuck, logs show timeouts on port 25. Your provider blocks outbound SMTP traffic. At netcup the default policy “netcup Mail block” (ports 25/465/587) is to blame: in the SCP under Firewall → Policies, take that netcup template off the server, no ticket needed, see netcup firewall setup. Without it, no delivery to other servers is possible.
Other servers don’t accept your mails or they land in spam. Missing or wrong PTR entry, no SPF/DKIM/DMARC. That’s not a Stalwart error but a matter of DNS/reputation configuration; see the email deliverability tutorial.
Your problem is not listed? Search all error messages →
Maintenance & backups
Updates are simple, because Stalwart is a single container:
cd /opt/stalwart
docker compose pull && docker compose up -dBefore bigger jumps, read the release notes on GitHub; stay on a specific version tag (like v1.1.1 here) instead of latest so updates remain reproducible. Stalwart releases roughly weekly. You don’t have to take every patch, but you shouldn’t sit still for months either. That applies within 1.x. If you still run 0.16, a new tag isn’t enough; the section Moving from 0.16 to 1.0 covers the switch.
When you go from 1.0 to 1.1, accounts, mail and folders stay as they are. New in 1.1 are passkeys, so signing in with a fingerprint or a security key. The default roles only get the permissions for them on a fresh install, though. A server coming from 1.0 keeps its old roles, and those lack the five sysPasskey* permissions. So after the update, start Stalwart once with this variable in the compose.yaml:
environment:
- STALWART_UPDATE_ROLE_PERMISSIONS=truedocker compose up -dAfter that the User and System Administrator roles have the new permissions. Take the two lines out again; the permissions stay after the next restart too.
For backups: all data (messages, accounts, settings and the DKIM keys) lives in the stalwart_data volume (/var/lib/stalwart); stalwart_config only holds the small config.json. Back up both volumes regularly away from the server, cleanest encrypted with Restic. Because Stalwart writes the data during operation, you back up most consistently by briefly stopping the container (docker compose stop), backing up the volumes and starting again. The DKIM keys are especially important: if they’re lost, your signatures break after a restore until you reset the DNS records. A backup you’ve never restored is just a hopeful guess; test the restoration once on a test system.
Also keep an eye on reputation. Occasionally check whether your server IP has landed on a block list, and take a look at the Stalwart console under Observability. A compromised mailbox that sends spam quickly ruins the reputation of your entire domain.
Moving from 0.16 to 1.0
Stalwart 1.0 stores its data in a new format, so a 0.16 store can’t be upgraded in place. If you only switch the tag to v1.0.3, startup aborts:
Server startup error (server.startup-error): details = The data store was created by a Stalwart version prior to 1.0 and cannot be opened by this version.The attempt isn’t entirely harmless either. 1.0 writes an entry into the old store that 0.16 can no longer read afterwards and reports as Registry read error on every start. So don’t try it; use the official stalwart-migrate tool. It copies accounts, mails, folders, Sieve scripts, DKIM keys and settings into a new, empty 1.0 store. Folders keep their IMAP UIDs and their UIDVALIDITY, so mail programs don’t download everything again. The tool only reads the old volumes. It requires 0.16.27. If your tag is older, bump it to that first.
1. Take a backup. Stop Stalwart and pack both volumes into an archive. It’s your way back if something doesn’t fit after the switch:
cd /opt/stalwart
docker compose stop
docker run --rm -v stalwart_stalwart_config:/etc/stalwart -v stalwart_stalwart_data:/var/lib/stalwart \
-v /root:/backup debian:13 tar -czf /backup/stalwart-0.16.tar.gz /etc/stalwart /var/lib/stalwartThe volume name carries the folder name as a prefix: /opt/stalwart turns into stalwart_stalwart_data. docker volume ls shows you the right names.
2. Add the migration service. Extend the compose.yaml with a second service and three new volumes. The migrate profile keeps it from starting with every up:
migrate:
image: stalwartlabs/stalwart-migrate:1.0.7
profiles: [migrate]
volumes:
- stalwart_config:/etc/stalwart:ro
- stalwart_data:/var/lib/stalwart
- stalwart_v1_config:/etc/stalwart-v1
- stalwart_v1_data:/var/lib/stalwart-v1
- stalwart_migrate:/var/lib/stalwart-migrate
volumes:
stalwart_config:
stalwart_data:
stalwart_v1_config:
stalwart_v1_data:
stalwart_migrate:The migrate: block goes under services: next to stalwart:; the volumes: block replaces the existing one at the end of the file. Tool and target go together: stalwart-migrate 1.0.6 and later requires Stalwart 1.0.3 or newer.
3. Describe the new store. The tool needs a config.json for the target. It names the path under which the 1.0 container will later see its data:
docker compose run --rm --entrypoint sh migrate -c \
'printf "%s\n" "{\"@type\":\"RocksDb\",\"path\":\"/var/lib/stalwart/\"}" > /etc/stalwart-v1/config.json'4. Prepare the switch. prepare reads the 0.16 settings, converts them to 1.0 and asks you about them:
docker compose run --rm migrate prepare --source /etc/stalwart/config.json --state /var/lib/stalwart-migrateThere are four questions: which kinds of data come along, how changed defaults are handled, how OAuth clients are treated and whether roles receive the new permissions. For a single server, the suggestions in square brackets fit each time, so press Enter. At the end you confirm with Y, and the tool stores its answers in the stalwart_migrate volume.
5. Copy. Stalwart has to be stopped for this. The tool asks and aborts if anything still moves in the old store:
docker compose stop stalwart
docker compose run --rm migrate run --final \
--source /etc/stalwart/config.json --target /etc/stalwart-v1/config.json \
--target-path-map /var/lib/stalwart=/var/lib/stalwart-v1 \
--state /var/lib/stalwart-migrateType yes when the tool asks. --target-path-map is needed because the tool sees the new store under /var/lib/stalwart-v1, while the 1.0 container mounts it under the usual /var/lib/stalwart. For a handful of mailboxes the run takes about half a minute, because the tool first watches the old store for 30 seconds. At the end it compares both stores:
verify: 2 accounts checked, 0 mismatches, 0 not explained by earlier reports (ok)The warnings in the report concern settings that no longer exist in 1.0, such as individual OAuth options and dropped permissions.
6. Switch to 1.0. In the stalwart service you swap image and volumes:
image: stalwartlabs/stalwart:v1.0.3
# …
volumes:
- stalwart_v1_config:/etc/stalwart
- stalwart_v1_data:/var/lib/stalwartdocker compose up -d stalwartAccounts, passwords, folders, Sieve rules and the DKIM selectors are the same as before. 1.0 rebuilds the search index in the background.
The roles come over in full as well. The System Administrator role receives every permission 1.0 knows, so under Settings you also find the Encryption section, for example. If you migrated with a version of the tool older than 1.0.6, the role lacks these permissions. In that case, start Stalwart once with an extra variable that gives the default roles all current permissions:
environment:
- STALWART_UPDATE_ROLE_PERMISSIONS=trueAfter docker compose up -d stalwart the variable has done its job; remove the two lines again.
The tool writes the new store for 1.0.3, which is why that tag is shown above. Once 1.0.3 runs cleanly, move up to the current version as described under Maintenance & backups, including the one-time start with STALWART_UPDATE_ROLE_PERMISSIONS.
What changes for users: OAuth sign-ins from 0.16 don’t carry over, so apps using OAuth sign in once more. Calendar and contacts apps fetch their data once completely.
To clean up: once 1.0 has run cleanly for a few days, remove the migrate service from the compose.yaml and delete the old volumes with docker volume rm stalwart_stalwart_config stalwart_stalwart_data stalwart_stalwart_migrate. Until then the archive from step 1 is your way back: set stalwart to v0.16.27 and the old volumes again, restore the archive, start:
docker compose stop stalwart
docker run --rm -v stalwart_stalwart_config:/etc/stalwart -v stalwart_stalwart_data:/var/lib/stalwart \
-v /root:/backup debian:13 sh -c 'rm -rf /etc/stalwart/* /var/lib/stalwart/* && tar -xzpf /backup/stalwart-0.16.tar.gz -C /'
docker compose up -d stalwartMails that arrived after the switch to 1.0 are then missing in 0.16.
Send feedback: feedback@serverkueche.de
What's next?

You might also like


