Webmail (snappymail)
Webmail on a Self Host Wizard box: the snappymail piece, served at webmail.<apps domain>, forward sign-in, memory limit 192 MB.
At a glance
| Field | Value |
|---|---|
| Address | https://webmail.<apps domain> |
| Sign-in | forward: Caddy asks Authelia before the app sees a request (forward auth) |
| Memory limit | 192 MB (ram_mb: measured peak × 1.3) |
| Database | none shared: it keeps its own data in THX_DATA |
| Needs | stalwart, authelia |
| Needed by | nothing |
| Containers | snappymail |
Image: snappymail | djmaze/snappymail:v3.1.4-1@sha256:13006205801c5f3e365738265f69289f9e8eb68870e17cd08859396c3c9fc341 |
| Licence (from the README) | AGPL-3.0 |
| Upstream (from the README) | https://github.com/the-djmaze/snappymail |
Turn it on
thx enable adds snappymail and everything it needs to the box's state; thx apply then installs it. Apps are applied only once site_domain is set.
sudo thx enable snappymail
sudo thx apply
Engineering notes (pieces/snappymail/README.md)
Webmail at webmail.<apps_domain>. The person signs in once, at Authelia. SnappyMail then opens their
own mailbox in Stalwart with no second password and no setup screen. It keeps no accounts, only
per-user settings.
auth = "forward": every path is behind Caddy's forward_auth, and Caddy replaces client-sent
Remote-* headers with Authelia's answer. SnappyMail never binds to LLDAP, so it gets no THX_LDAP_*
and lldap is not on its network.
Upstream: the-djmaze/snappymail v3.1.4, AGPL-3.0. Image
djmaze/snappymail:v3.1.4-1@sha256:13006205…c9fc341 (the maintainer's), a multi-arch index with
linux/arm64 (docker buildx imagetools inspect, 2026-11-24).
How the mailbox opens
Master user. Stalwart lets the LLDAP service user
thx-snappymail@<apps_domain>impersonate (the stalwart piece grants it while snappymail is inTHX_PIECES). Its password is this piece'sldap_passwordsecret, and core keeps that user (lane report).- IMAP and SMTP log in as
<person's address>%thx-snappymail@<apps_domain>with the master password. - The person's own password is never asked for and never used.
- IMAP and SMTP log in as
- **
scripts/thx-guard.php** is PHP'sauto_prepend_file, so it runs before SnappyMail on every request. A request without exactly one well-formed address inRemote-Emailgets 403 and nothing else (pages, JSON API and the?ThxLoginhook alike). **
scripts/thx-ssoplugin:**?ThxLogin(custom_login_link) logs inRemote-Email's mailbox and redirects to the app. A person without a mailbox gets 503, not a redirect loop.- Every IMAP, SMTP and Sieve login is rewritten to the master login, and only for the address in
Remote-Email. A login for any other address (the Login action, AccountSetup) is refused. - Before SnappyMail reads its session cookie, a cookie that belongs to someone other than
Remote-Emailis dropped. Example: the same browser after another person signed in to Authelia. - Upstream bug worked around: SnappyMail 3.1.4's
filter.accounthook cannot stop such a cookie.Account::NewInstanceFromTokenArrayreturns the account even when the hook throws, because the index page and AppData call it withthrow = false. The test caught alice's session being served to bob's header.
- The master password reaches PHP through a tmpfs file (
/run/thx, root:www-data 0440). php-fpm clears the environment, and the variable is unset after the copy. - TLS. IMAP 993 and SMTP 465 are implicit TLS with certificate verification on
(
files/default.json:verify_peer, no self-signed).mail.<apps_domain>resolves to Stalwart itself: apply connects stalwart to this piece's network with that alias, and Stalwart serves the samemail.certificate there, so TLS verifies without leaving the box. Settings.
scripts/thx-init.shruns before the image's/entrypoint.shon every start. Inapplication.iniit sets:- no admin panel;
- no additional accounts;
cookie_default_secure = On(Caddy terminates TLS);- the login link
./?ThxLogin; - the logout link
https://auth.<apps_domain>/logout, so signing out ends the Authelia session.
It checks that the key lines landed.
Measured (dev PC, amd64, test.sh, 2026-11-25)
snappymail 121 / 94 MB peak (two runs, docker stats every second; sign-in, send, list, restart)
ram_mb = 192, not 121 × 1.3 = 157. One PHP request may use up to MEMORY_LIMIT = 128 MB (a large
attachment), and the test never does.
test.sh
The stalwart piece's throwaway stack (../stalwart/test/stack.sh, which keeps thx-snappymail in
LLDAP), then SnappyMail as its own compose project on its own piece network. The test drives
SnappyMail's JSON API the way the browser does, with the Remote-* headers Caddy would set sent by
hand.
It proves:
- No
Remote-Email, an empty one, a bare name or two addresses → 403 on/, Ping, AppData,?ThxLoginand the JSON API. - alice opens webmail signed in, with no password, and every cookie is
Secure. Sign-out goes to Authelia's logout. - alice and bob (another company's domain) each send over 465 and see only their own mail.
- alice's session cookie with
Remote-Emailbob is not signed in and gets no mailbox. - Inside alice's session, Login as bob (with bob's real password) and AccountSetup for bob are refused.
- A signed-in person without a mailbox gets 503. The admin panel is off.
- All of the above again after a restart.
- Without the test CA,
?ThxLogingets 503: the master password is never sent to a server SnappyMail cannot verify. - The master password is not in the log, plain or base64.
It prints PASS snappymail ram_peak_mb=<n>.
Mutations that make it fail (2026-11-25): no guard (/ without a header answered 302), and no
identity check in the plugin (alice logged in as bob).
Known gaps
- Core must keep the LLDAP user
thx-snappymail@<apps_domain>with this piece'sldap_password(lane report). Without it,?ThxLoginanswers 503. - Contacts are SnappyMail's own (per user, in
THX_DATA); no CardDAV link to Radicale yet. org-*groups mean nothing here.