Stalwart Mail Server
Container
All-in-one mail server supporting SMTP, IMAP, JMAP, and more, with a built-in web administration interface. Source: https://github.com/stalwartlabs/stalwart
Image details
Source details
Configuration
TypeContainerlinuxstalwartlabs/stalwart:latest8080:8080/tcp443:443/tcp25:25/tcp587:587/tcp465:465/tcp143:143/tcp993:993/tcp/etc/stalwart/var/lib/stalwartSTALWART_RECOVERY_ADMIN=unless-stoppedNotes
Standalone Install
Select an install method, to see config/commands for deploying Stalwart Mail Server
Install on Portainer
Import all app templates into your Portainer instance, for easy 1-click deploys
- Ensure both Docker and Portainer are installed, and up-to-date
- Log into your Portainer web UI
- Under Settings → App Templates, paste the below URL
- Head to Home → App Templates, and the list of apps will show up
- Select Stalwart Mail Server, fill in any config options, and hit Deploy
Template Import URL
https://raw.githubusercontent.com/Lissy93/portainer-templates/main/templates.json
Show Me
More install options in our documentation, or see stalwartlabs/stalwart for app-specific guidance.
Stalwart Mail & Collaboration Server
Stalwart is an open-source mail & collaboration server with JMAP, IMAP4, POP3, SMTP, CalDAV, CardDAV and WebDAV support and a wide range of modern features. It is written in Rust and designed to be secure, fast, robust and scalable.To get started, pull the
stalwart:latest image, for example:$ docker pull stalwartlabs/stalwart:latestThen, create a directory on your host machine where you will store the configuration files and the data for the mail server, for example:
$ mkdir /var/lib/stalwartOnce you have completed the setup instructions, start the Stalwart container:
$ docker run -d -ti -p 443:443 -p 8080:8080 \
-p 25:25 -p 587:587 -p 465:465 \
-p 143:143 -p 993:993 -p 4190:4190 \
-p 110:110 -p 995:995 \
-v <STALWART_DIR>:/opt/stalwart \
--name stalwart stalwartlabs/stalwart:latestMake sure to replace
<STALWART_DIR> with the path to the directory you created above. Please note that it is not necessary to expose all these ports, read the securing your server documentation for more information.Log in to the web interface
Executedocker logs stalwart to obtain the system the administrator account and password: $ docker logs stalwart
✅ Configuration file written to /opt/stalwart/etc/config.toml
🔑 Your administrator account is 'admin' with password 'w95Yuiu36E'.With this information, you can log in to the web interface at
http://yourserver.org:8080/login.Choose where to store your data
Once you have logged in, go to theSettings > Storage section and configure your data, blob, full-text and in-memory stores. Read the choosing a database section for more details on the available options. If you would like an external authentication directory such as LDAP or SQL, go to the
Settings > Authentication section and configure your authentication backend.:::tip Optional
Stalwart comes pre-configured with
RocksDB as the default backend for all stores. You can skip this step if you are happy with the default configuration.:::
Configure your hostname and domain
Next, make sure that the server hostname inSettings > Server > Network is correct. Then, add your main domain name in Management > Directory > Domains. After creating the domain, the interface will display the DNS records that you need to add to your domain's DNS settings. For example:
MX example.org. 10 mail.example.org.
TXT 202404e._domainkey.example.org. v=DKIM1; k=ed25519; h=sha256; p=MCowBQYDK2VwAyEAOT2JN9F8SLTVFNEODDu22SD9RJDC282mugCAeXkzjH0=
TXT 202404r._domainkey.example.org. v=DKIM1; k=rsa; h=sha256; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAykeYJjv5N0AlnJ8gKF+/8qjbStiMFWvPg+p3JPh96GPXEN6l9W/Ee6Lag6i3vLyTVH5dnRVRBhfWhc+Dc0nKreZe4f5i4L5M4RI31+RpEgu4bCmncUIk2WzJgGBW5XbiOwXjge6OKWtJQN9d8Lc1AuryL5xeged9iS6xd/+EJz4WxAf18U+j38xmAm8fJUTBnQVeb/AZup+voSKAS59jyumsb0jQtXfX5xnwTFXdiX2OF8LRrmmNs/ObHozgHftxAv+YCiSU4bqSlKNPQIrN5kk1YnZDnLlc1Gr66AWlmdUVE7PWtZPTy4f8+uHO93EW3WUxLmynZm+Syn9FTJC2uwIDAQAB
TXT mail.example.org. v=spf1 a -all ra=postmaster
TXT example.org. v=spf1 mx -all ra=postmaster
TXT _dmarc.example.org. v=DMARC1; p=reject; rua=mailto:postmaster@example.org; ruf=mailto:postmaster@example.org:::tip
Some of the autogenerated records may be optional depending on your setup, read the setting up DNS section for more information.
:::
Enable TLS
Stalwart requires a valid TLS certificate to secure the connection between the server and the client. You can enable TLS in one of the following ways:- If you already have a TLS certificate for your server, you can upload it in the
Settings>Server>TLS>Certificatessection. - If you don't have a certificate, you can enable automatic TLS certificates from Let's Encrypt using ACME. To enable ACME, go to the
Settings>Server>TLS>ACME Providerssection and add Let's Encrypt as your ACME provider making sure that your server hostname is listed as one of the Subject Names. Stalwart supports thetls-alpn-01,dns-01andhttp-01challenges, if you are unsure which one to use, read the ACME challenge types documentation. - If you are running Stalwart behind a reverse proxy such as Traefik, Caddy, HAProxy or NGINX, you should skip this step and configure TLS in your reverse proxy instead.
Restart the container
Once you have completed the setup instructions, restart the container:$ docker restart stalwartNext steps
If you have selected to use the internal directory, you can now add your users in theManagement > Directory > Accounts section. If you have selected an external directory, you will need to create users in your directory server.If everything went well, your users should now be able to connect to the server and send and receive emails. If you are unable to connect to the server, check the log files from the web-admin or under
<INSTALL_DIR>/logs for any errors.If you encounter any issues, please refer to the troubleshooting section for help. If you have questions please check the FAQ section or start a discussion in the community forum.
:::tip
Before making your server publicly accessible, please make sure to read the securing your server section.
:::
Serve Stalwart Mail Server on your own domain behind Caddy, Nginx or Traefik. Fill in your domain and copy the result. It's a starting point, some apps need their own base URL or extra headers set too.
Proxying stalwart-mail-server.example.com to http://stalwart-mail:8080
Add this to your Caddyfile
stalwart-mail-server.example.com {
reverse_proxy http://stalwart-mail:8080
}Check the logs first
Nine times out of ten the logs tell you exactly what went wrong.
- In Portainer, go to Containers, click the container, then Logs. Or run
docker logs stalwart-mail - Exit codes help too:
137means killed, usually out of memory.126or127means the command inside the image is broken.
Port already in use
If deployment fails with "Bind for 0.0.0.0:8080 failed: port is already allocated", something else on your server is using that port.
- Find what's using it:
sudo ss -tlnp | grep :8080 - Stop the other service, or pick a different host port. In
8080:8080only the left number is yours to change, the right one belongs to the app.
Running but the page won't load
The container is up but nothing appears in your browser.
- Use your server's real IP:
http://your-server-ip:8080. The 0.0.0.0 link Portainer shows isn't a real address. - Give it a minute after first deploy, stalwart-mail can take a while to initialise.
- Make sure your firewall allows the port, e.g.
sudo ufw allow 8080
Image won't pull
Test the pull directly on the host: docker pull stalwartlabs/stalwart:latest
- "manifest unknown" means the tag no longer exists. This template uses
latest, so try pinning a specific version instead. - "toomanyrequests" is the Docker Hub rate limit. Log in with
docker loginto raise it. - "no space left on device" means a full disk. Reclaim space with
docker system prune
"exec format error"
This means the image was built for a different CPU architecture than your server.
- This image supports:
amd64, arm64, arm/v7, arm/v6 - Check yours with
uname -m: x86_64 is amd64, aarch64 is arm64. Raspberry Pi and other ARM boards are the usual culprits.
Container keeps restarting
The unless-stopped restart policy relaunches the app after every crash, so the real error can scroll past.
- Check the logs right after a restart, the last few lines before it died are the useful ones.
- Get the exit code with
docker inspect stalwart-mail --format '{{.State.ExitCode}}' - Still stuck? Redeploy once with the restart policy set to
noso the failure stays visible.
Required settings are blank
STALWART_RECOVERY_ADMIN has no default value, and stalwart-mail may crash or misbehave if left empty.
- Fill it in on the deploy screen before hitting deploy.
Raise an issue
Found something which isn't working as it should? Here's how to report it.
- Bug within the app: Open an issue on stalwartlabs/stalwart
- Template not working: Open an issue within the template's repo
- This website not working: Open an issue on lissy93/portainer-templates
A single container
Stalwart Mail Server runs as one container, the simplest kind of app here. Just the one image to pull and nothing else wired up alongside it.
The app image
An image is the app packed up ready to go, everything Stalwart Mail Server needs bundled into one download. This template pulls stalwartlabs/stalwart:latest, which Docker fetches once (about 86 MB) and then starts your own copy from.
Where the image comes from
Docker pulls its images from registries, public libraries of ready-built apps. Stalwart Mail Server's comes from Docker Hub, published by stalwartlabs.
Version tags
The bit after the colon in the image name is the version tag. Here it's latest, which always points at the newest build, so a redeploy can bump you to a newer release without you asking. Newest right now is v0.16.17. Pin a specific tag if you would rather stay on one version.
Which machines it runs on
Every image is built for particular CPU types. This one ships for amd64, arm64, arm/v7, arm/v6, so it runs on both regular x86 servers and ARM boards like a Raspberry Pi.
Ports
A port is the door the app answers on. A mapping like 8080:8080 means it's reachable on port 8080 of your server, where the left number is yours to change and the right one belongs to the app. Once it's running, open http://your-server-ip:8080 in a browser. It opens:
8080:8080, likely the web interface443:443, likely the web interface25:25587:587465:465143:143993:993
Volumes
A volume is where Stalwart Mail Server keeps its files so they survive an update or a restart. Without one, anything it saves would sit inside the container and vanish the moment it's recreated. This template mounts:
/etc/stalwartas a volume Docker manages for you/var/lib/stalwartas a volume Docker manages for you
Environment variables
Environment variables are the settings you hand over when you deploy, things like a password or a timezone. Stalwart Mail Server takes 1 of them, and one needs a value before it'll start properly:
STALWART_RECOVERY_ADMIN, needs a value. Fallback admin as username:password (optional; blank = random password printed to logs)
Restart policy
The restart policy here is unless-stopped, so Docker restarts Stalwart Mail Server after a crash or reboot, but leaves it off when you stop it on purpose. You can change this on the deploy screen. The choices are no (never restart), on-failure (only after a crash), unless-stopped (restart unless you stop it), and always (bring it back no matter what).
Networking
Nothing custom is set, so Stalwart Mail Server sits on Docker's default bridge network: its own private space that reaches the outside world only through the ports it publishes.
Container name
Once it's deployed, Portainer names the container stalwart-mail. That's what you'll spot in the containers list and use in commands like docker logs stalwart-mail.
Platform
The platform is linux, the kind of system the container is built to run on. Docker and Portainer handle this on a normal Linux server.
Portainer app templates
Zooming out, this whole page comes from a Portainer app template: a short recipe telling Portainer how to set Stalwart Mail Server up. Add the template list to Portainer once, then deploying Stalwart Mail Server is a click rather than a wall of config.