Your question
Question
If I do curl http://mail.vpn.<public-domain>/jmap/session, I’m getting http://mail.<public-domain> for the apiUrl for example. How can I change the host within the apiUrl entry to http://mail.vpn.<public-domain>?
Context
I’m the only client and I’d like to only allow users (me) within the vpn to connect to the stalwart mail server (except the SMTP(S) ports to retrieve mails of course) so basically every path is only accessible within my VPN in a vpn-subdomain while the server itself is accessible by the public domain.
What I’ve tried
Added mail.vpn.<public-domain> in Settings > Network > Services > Services > JMAP > Hostname, then pressed Save. Then went to Management > Actions > Server settings.
Afterwards, curl http://<vpn-subdomain> still returns the public-domain in apiUrl (and other entries) if I lookup http://<vpn-subdomain>/jmap/session.
I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.
on
The STALWART_PUBLIC_URL environment variable is what you need. The apiUrl (and all other discovery URLs for JMAP, OAuth, OIDC) are built from a single base URL derived from defaultHostname. Setting the hostname field in the WebUI only changes defaultHostname, which is used for SMTP greetings and as a fallback – it does not override the full base URL used in discovery documents.
To make /jmap/session return http://mail.vpn.<public-domain> as the base for apiUrl and friends, set the STALWART_PUBLIC_URL environment variable before starting Stalwart:
STALWART_PUBLIC_URL=https://mail.vpn.<public-domain>
A few important notes:
- This variable replaces the scheme, host, port, and optional path prefix in every published discovery URL.
- It does not affect Stalwart’s internal listener bindings (those are configured via
NetworkListener objects).
defaultHostname continues to be used independently in SMTP greetings and outgoing message headers, so update that separately in Settings > Network > Services if needed.
See the full details in the Environment Variables documentation.
This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.