概要
Step-by-step guides for self-hosting a mail server on a small VPS: Stalwart, Bulwark webmail, nginx, Unbound, acme.sh, MXroute relay, restic backups. Tested on 1 GB RAM.
システム・インフラ計測したスター増加
- 24時間
- 0
- 7日間
- 履歴を収集中
- 15日間
- 履歴を収集中
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
README.md
オリジナルSelf-Hosted Mail Server Guide
A complete, copy-paste guide to running your own mail server on a 1 GB VPS: Debian 13 + Stalwart + Bulwark webmail + nginx + Unbound + acme.sh + MXroute relay + restic backups. Written from a real deployment, with 37 pitfalls documented.
Written for the LowEnd crowd. The hard part of self-hosting mail is not installing it. It is getting mail delivered, staying out of the spam folder, getting certificates and DNS right the first time, and knowing where to look when something breaks. This guide uses a netcup 1 vCore / 1 GB RAM / 30 GB SSD VPS as the example. It starts from a fresh Debian 13 install and goes all the way to multi-domain hosting, a unified signature, anti-spam and off-site backups. Every step comes with copy-paste commands and configs, and every pitfall I hit during the real deployment is written down (Section 21; check there first when troubleshooting).
Problems this solves:
- Mail from a new IP lands in Gmail spam → relay through MXroute, with direct delivery from the server as fallback (Section 16)
- Port 25, PTR and HELO don't match → one consistent hostname for hostname, PTR and HELO (Sections 3, 4)
- SPF / DKIM / DMARC / MTA-STS / TLS-RPT / DANE all set up in one go, with DNS records published automatically by Stalwart (Sections 11–13)
- Certificates fighting each other (wildcards,
_acme-challengeconflicts) → nginx and Stalwart each issue their own, only for the names actually used (Sections 7, 11) - Phones, Thunderbird and Outlook configure themselves from just the address and password (autoconfig / autodiscover / SRV)
- Anti-spam blocklist lookups all refused (
_BLOCKED) → local recursive resolver with Unbound (Section 6.2) - Runs on 1 GB RAM: the whole stack uses about 600 MB in practice (with 2 GB swap)
- Hosting customer domains (
mail.<customer-domain>), one signature across all domains, automatic backups to a NAS at home (Sections 18, 19)
Conventions: The main domain is example.com (server mta.example.com, clients and admin mail.example.com, webmail webmail.example.com), the customer domain is client.com, and the server IPs are 203.0.113.10 / 2001:db8::10. Replace them with your own. Version numbers are kept as-is so you can judge how current things are.
Tech Stack
| Component | Role | Why this one |
|---|---|---|
| VPS: netcup 1 vCore / 1 GB / 30 GB, Debian 13 | Runs everything | Cheap, you can set PTR yourself, outbound port 25 is available |
| linux-server-init | System initialization | One command for firewall (nftables, no conflict with Docker), key-only SSH, automatic updates, swap and BBR; safe to re-run |
| Stalwart v1 (Docker, host network) | The mail server | All-in-one mail server written in Rust: SMTP, IMAP, POP3, JMAP, ManageSieve, anti-spam, DKIM/SPF/DMARC/ARC/DANE, ACME certificates, automatic DNS management and a web admin, all in one binary. The classic stack is Postfix + Dovecot + Rspamd + Redis + a database + an admin panel glued together (mailcow's official minimum is 6 GB RAM + 1 GB swap); Stalwart runs on a 1 GB VPS |
| Bulwark | Webmail | Modern UI, the browser talks JMAP directly to Stalwart, thin backend with a small memory footprint; supports per-domain branding |
| nginx mainline (nginx.org repo) | HTTPS reverse proxy | Serves the web admin, webmail, client autoconfig and MTA-STS; supports HTTP/3. Mail ports do not go through nginx |
| acme.sh + Cloudflare DNS-01 | Certificates for nginx | Only the names actually used, no wildcard, no fighting over _acme-challenge with certificates elsewhere |
| Cloudflare DNS (all DNS-only, grey cloud) | DNS hosting | The API lets Stalwart publish DKIM, SPF, DMARC and other records automatically |
| MXroute | Outbound relay | A new IP has no reputation, so direct delivery tends to land in spam. Mail goes through MXroute first and is delivered directly only after two failed attempts |
| Unbound (on the host) | DNS resolver for Stalwart | Public resolvers and provider resolvers get refused by blocklists; a local recursive resolver makes anti-spam actually work and also supports DNSSEC/DANE |
| restic + NAS pull | Backups | Daily encrypted snapshots; the NAS at home pulls them with read-only access and keeps 30 daily copies, so you can recover even if the server is compromised and the local backup deleted |
| Sieve system script | Unified signature | Each domain's signature lives in a key-value store, one script serves all domains, and individual accounts can be excluded |
Guide Contents
Follow the parts in order for a new server. Multi-domain hosting and the signature are optional.
- Installation: Architecture, server init, nginx, Docker, Unbound, acme.sh, Stalwart deployment and first-login fixes (Steps 1–8).
- DNS and TLS: Automatic DNS and ACME in Stalwart, manual SPF/DMARC/SRV records, MTA-STS (Steps 9–11).
- Accounts and Webmail: Accounts, RFC 2142 aliases, quotas, DMARC/TLS report analysis, Bulwark webmail (Steps 12–13).
- Outbound Relay and Testing: MXroute relay with direct-delivery fallback, rate limits, and the final test checklist (Steps 14–15).
- Hosting Customer Domains: Adding customer domains with their own mail. hostname, certificates, autoconfig and relay.
- Server-Side Unified Signature: One Sieve script that adds a per-domain signature to all outgoing mail, placed above quoted text.
- Backup and Restore: Daily restic snapshots, NAS pull with dated hard-link copies, Docker auto-updates, restore (Step 16).
- Operations Cheat Sheet: Day-to-day status, log and certificate checks, memory reference.
- Troubleshooting: 37 pitfalls hit during the real deployment, with causes and fixes.
Repository Layout
selfhosted-mail-guide/
├── README.md this page: overview and contents
├── CHANGELOG.md
├── LICENSE CC BY 4.0
├── docs/ the guide, one file per part (links above)
├── configs/ files that go on the server, linked from the docs
│ ├── nginx/ conf.d/ and snippets/
│ ├── unbound/ local resolver for Stalwart
│ ├── docker/ daemon.json
│ ├── stalwart/ compose.yaml
│ ├── bulwark/ compose.yaml
│ ├── systemd/ backup and update timers
│ └── autoconfig/ static autoconfig/autodiscover XML for customer domains
├── scripts/ backup, update and NAS pull scripts
└── sieve/ signature-engine.sieve
Each config file is shown in the docs with a link and a curl command that downloads it to the right place. Files containing example names (example.com, client.com, 203.0.113.10, <SSH_PORT> …) must be edited after downloading; the docs say so next to each one.
Summary
After these 16 steps you have a complete mail system on a 1 GB VPS:
- Sends and receives, stays out of spam: SPF, DKIM, DMARC, MTA-STS, TLS-RPT and DANE all in place, 10/10 on mail-tester; outbound goes through MXroute to borrow its reputation, with direct delivery as the fallback.
- Easy to use: webmail (Bulwark), and phone and desktop clients configure themselves from just the address and password; IMAP, POP3, JMAP, calendars and contacts all included.
- Hosts other people's domains: each customer domain uses its own
mail.<customer-domain>, with its own certificate, branding and unified signature, and customers can't see each other's accounts in webmail. - Anti-spam that actually works: a local recursive Unbound resolver, so blocklist queries are no longer refused, plus DNSSEC/DANE support.
- Hard to lose: daily encrypted restic snapshots, pulled read-only by the NAS at home with 30 days of history, so you can recover from the NAS even if the server is compromised and the local backup deleted.
- Light on resources: about 600 MB of memory for the whole stack in practice; the cheapest 1 GB VPS is enough.
The lessons most worth remembering:
- Don't expect a new IP to land in the inbox with direct delivery. However perfect the config, no reputation means spam; a relay is the least painful way out. Build reputation gradually with Postmaster Tools.
- Hostname, PTR, HELO and certificate names must match. A lot of "mysterious rejections" come from here.
- Each side issues its own certificates, only for the names used. nginx uses acme.sh, Stalwart uses its own ACME, no wildcards, and they never overwrite each other.
- The DNS resolver matters. Public DNS silently disables every blocklist check, and the report only shows
_BLOCKEDwith 0 points, which is easy to miss. - Many Stalwart settings only apply after Reload or a restart, and key-value changes need Reload Lookup Stores. If a change has no effect, first check whether you did this step.
- Always test for real after a change: send a message to Gmail and look at SPF/DKIM/DMARC,
X-Spam-Resultand the headers in the original. That's far more reliable than looking at the admin config. - Back up before you touch anything. Screenshot or copy before changing scripts or rules, so you can roll back immediately.
When something goes wrong, check the pitfalls in Section 21 first; for routine work see Section 20. Happy self-hosting, and may all your mail land in the inbox!
License
CC BY 4.0. You may share and adapt this guide, including commercially, as long as you give credit and link back to this repository.
Contributing
Corrections are welcome via issues or pull requests. Software changes quickly: if a step no longer matches the current Stalwart, Bulwark or another component, please open an issue with the version you're running. See CHANGELOG.md for what changed.
関連プロジェクトを探す
読み込み中…