Stalwart Mail Server with Docker and Traefik
Deploy a Stalwart all-in-one mail and collaboration server in Docker with an HTTPS web UI behind Traefik and an automated first-run setup.
Summary
- Category
- Jet Templates
- Tags
- Authors
- Cetmix OÜ
- License
- AGPL-3
- Version
- 1.0.0
- Call sign
- jet_template_stalwart_docker
- Website
- cetmix.com/contact
This snippet imports a Stalwart Mail Server Jet Template using stalwartlabs/stalwart:v1. It allows one instance per server and runs SMTP, IMAP, POP3, JMAP, CalDAV and CardDAV in a single container. Configuration and mail are stored in two named Docker volumes labelled with the Jet reference. The web UI is served over HTTPS through a running Traefik Jet and reaches Stalwart on its internal HTTP port 8080. Mail ports 25, 465, 993, 995 and 4190 are published directly on the host, because Traefik cannot proxy them. Port 8080 is also published on the host loopback only. The Traefik, Docker, Fail2ban and Tower Core dependency templates are included.
Before you start
- The server needs a public IPv4 address, outbound port
25and a reverse DNS (PTR) record for that address that matches the Jet hostname. Many hosting providers block port25by default, so check this first. - Import the YAML and install the template on the server. Open the host firewall for the published mail ports and for ports
80and443used by Traefik. - Set the Stalwart Recovery Admin secret as
admin:<password>. Use only letters, digits, underscore and hyphen, and a password of at least 16 characters. - Configure the hostname and DNS. With Cloudflare DNS registration, set
web_domain,cloudflare_tokenandcloudflare_zone_id. For other DNS providers, make sure the Jet has a URL and a matching DNS record. Set the Traefikinstance_certbot_emailto a valid contact address, for exampleadmin@example.org. For a Traefik DNS challenge, set the selected provider's credentials (cloudflare_token,digitalocean_api_token,hetzner_api_token, oraws_dns_key_idandaws_dns_access_key).
Deploy
- Create a Jet and set
stalwart_mail_domainto your primary mail domain, for exampleexample.com. Target Running. - Prepare locks the Jet against deletion, sets the Jet URL, registers the DNS record, validates the configuration and creates the volumes. Build pulls the image and creates a stopped container. Start starts it and waits until it is healthy.
- On a Jet that was never set up, Start also runs the automated first-run setup through the Stalwart management API and restarts the container. No wizard and no SSH tunnel are needed. It then applies the reverse-proxy settings, so bans and rate limits use the real client address from Traefik. The Docker private range
172.16.0.0/12is allow-listed, so the proxy cannot ban itself. - Sign in at
https://<jet hostname>/adminasadminwith the Stalwart Recovery Admin password. Configure ACME with the DNS-01 challenge in the admin UI, add mailboxes, and publish the MX, SPF, DKIM and DMARC records for your mail domain. - Once the setup is finished, set
stalwart_recovery_admin_modetodisabledand run Rebuild, so the recovery credentials are no longer passed to the container.
Operate and troubleshoot
Changed variables, secrets and the image tag are applied by Rebuild, not by Restart. Rebuild keeps all mail and configuration, but mail is unavailable while it runs. Remove deletes the container only and keeps the volumes and the deletion lock. Destroy permanently deletes all mail and configuration, the DNS record and the volumes. The Jet logs show the container output, the service health, the published ports and the setup status. If the web UI answers 502 behind Traefik, Stalwart has probably banned the proxy address. Review the allowed addresses in the admin UI. Start re-applies the reverse-proxy settings only while stalwart_recovery_admin_mode is enabled. If outgoing mail is rejected, check the PTR record, the SPF, DKIM and DMARC records and that outbound port 25 is open.
This package is distributed under the GNU Affero General Public License v3.0 (AGPL-3) or later.
These Terms and Conditions (“Terms”) govern your access to and use of YAML configuration files (“Packages”, “YAML Snippets”, or “Snippets”) made available via the Cetmix Tower platform, operated by Cetmix OÜ, Ranna 6, Haademeeste, Voiste, 86501, Estonia (“Cetmix”, “we”, “our”, or “us”).
By downloading, installing, or otherwise using any YAML Snippets from the Cetmix Tower platform, you agree to be bound by these Terms.
1. Use of Packages
1.1. The YAML Snippets are provided either by Cetmix or third-party authors (“Authors”).
1.2. You are solely responsible for verifying the functionality, safety, and suitability of any YAML Snippet before using it in a production environment.
1.3. You may use the Snippets only in accordance with their respective licenses, which may be open-source or commercial.
2. Author Responsibility
2.1. Authors are solely responsible for the content, accuracy, functionality, and compliance of the YAML Snippets they publish.
2.2. Cetmix does not review or verify the correctness, security, or compliance of third-party Snippets.
2.3. If you are an Author, you represent and warrant that your submitted YAML Snippet:
- Does not infringe on any third-party rights;
- Complies with applicable laws and regulations;
- Does not contain harmful, malicious, or misleading code or behavior.
3. Limitation of Liability
3.1. Cetmix provides access to the YAML Snippets “as is” and “as available,” without warranties of any kind, either express or implied.
3.2. Cetmix expressly disclaims all liability for any damages resulting from:
- Use or inability to use a YAML Snippet;
- Errors or omissions in the Snippets;
- Actions taken in reliance on any YAML Snippet;
- Misuse, misconfiguration, or system failure caused by a Snippet.
3.3. In no event shall Cetmix OÜ be liable for any indirect, incidental, special, punitive, or consequential damages, including but not limited to loss of data, profits, or service availability.
4. Security and Compliance
4.1. Cetmix does not guarantee that any Snippet is secure or free from vulnerabilities. You must review and test all Snippets before deploying them in sensitive or production environments.
4.2. Compliance with security, privacy, and regulatory requirements is your responsibility when using any Snippet.
5. Intellectual Property
5.1. Ownership of each YAML Snippet remains with its respective Author.
5.2. You must respect all license terms specified for each Snippet. Unauthorized reproduction, distribution, or sublicensing may result in legal consequences.
6. Modifications and Termination
6.1. Cetmix may modify or remove any YAML Snippet at any time without notice.
6.2. These Terms may also be updated periodically. Continued use of the platform constitutes acceptance of the revised Terms.
7. Governing Law and Jurisdiction
These Terms shall be governed by the laws of the Republic of Estonia. Any disputes arising under or in connection with these Terms shall be subject to the exclusive jurisdiction of the courts of Estonia.
8. Contact
For questions or concerns regarding these Terms or specific YAML Snippets, please contact us