Self-hosting email is one of the most rewarding—and most demanding—privacy projects you can run. Stalwart Mail Server offers a modern, open-source path to host mail, calendars, and contacts yourself, but successful delivery depends on DNS reputation, authentication, backups, and careful operations as much as on the mail software.

This guide explains the architecture and a practical Docker starting point. It complements our self-hosted privacy tools and Docker supply-chain security guide. Treat this as a deployment framework, not a promise that a brand-new VPS will immediately deliver reliably to Gmail or Outlook.

What Stalwart provides

Stalwart is a mail and collaboration server designed around modern protocols. Depending on the edition and configuration, it can provide SMTP for message transfer, IMAP for mail clients, JMAP for efficient access, and CalDAV/CardDAV services for calendars and contacts.

The appeal is a single self-hosted service with a modern administrative model and storage options suited to small installations. You retain control of mailboxes and can integrate the server with your own domain, password manager, and backup system.

Email remains a federated system, though. Your server must communicate with many independently operated providers, and those providers decide whether to accept your messages. Software choice is only one part of the result.

Before you deploy

You need a domain, a VPS or stable internet connection, a static public IP, reverse DNS control, and ports 25, 465, 587, 993, and any other required service ports available. Many residential ISPs block outbound SMTP, so a VPS is usually simpler.

Choose a hostname such as mail.example.com and make sure the server’s forward DNS and reverse DNS agree. A mismatch is a common reason for poor reputation. Start with one domain and a small number of mailboxes while you learn the system.

Do not use email as your only account-recovery channel during setup. Keep an independent admin address and store recovery codes securely offline.

Docker Compose starting point

The exact image tag and configuration keys should follow the current Stalwart documentation. Pin a reviewed release rather than deploying an unexamined floating tag.

services:
  stalwart:
    image: stalwartlabs/mail-server:latest
    container_name: stalwart
    restart: unless-stopped
    hostname: mail.example.com
    ports:
      - "25:25"       # SMTP
      - "465:465"     # SMTPS
      - "587:587"     # submission
      - "993:993"     # IMAPS
      - "443:443"     # HTTPS/JMAP/admin, if used directly
    volumes:
      - stalwart_data:/opt/stalwart
    environment:
      - STALWART_HOSTNAME=mail.example.com

volumes:
  stalwart_data:

The sample is intentionally conservative: consult the release documentation for the supported image name, configuration format, and service ports before starting. Bind administrative interfaces to a private network or protect them with a reverse proxy and firewall rules.

After creating the directory, start the container and inspect logs before opening accounts:

mkdir -p ~/services/stalwart
cd ~/services/stalwart
# save compose.yaml
 docker compose pull
 docker compose up -d
 docker compose logs --tail=100 stalwart

For production, use an immutable digest, run the container with only required privileges, and keep secrets outside the Compose file. Our Docker security article covers those controls in detail.

DNS is part of the mail server

Create an A or AAAA record for the mail hostname. Set the VPS reverse DNS to the same hostname. Then publish an MX record for the domain:

example.com.        MX 10 mail.example.com.
mail.example.com.   A  203.0.113.10

You also need SPF, DKIM, and DMARC. SPF states which servers may send for the domain. DKIM signs outgoing messages. DMARC tells receiving providers how to evaluate authentication alignment and where to send reports.

A conceptual starting point is:

example.com. TXT "v=spf1 mx -all"
_dmarc.example.com. TXT "v=DMARC1; p=none; rua=mailto:[email protected]"

Stalwart will provide or help generate the DKIM selector and public key. Publish the exact record it gives you; do not invent a key value. Begin DMARC monitoring with p=none, inspect reports, then move toward quarantine or reject once legitimate senders are known.

TLS and user access

Use valid certificates for the mail hostname and renew them automatically. Mail clients need TLS for IMAP and submission, while web administration and JMAP should use HTTPS.

Disable plaintext authentication on public interfaces. Require authenticated submission on port 587, use strong individual passwords, and enable multi-factor authentication if the installed version and client workflow support it.

Separate administrator accounts from ordinary mailboxes. A compromised mailbox should not automatically provide server administration. Rate-limit login attempts and monitor authentication failures.

Deliverability is the hard problem

A technically correct message can still land in spam. New IP addresses have little reputation, and shared VPS ranges may have a history you cannot control. Keep volumes low at first, send only to people who expect the mail, and never use a new server for bulk campaigns.

Check that your IP is not on major blocklists, ensure forward and reverse DNS are consistent, and test SPF, DKIM, and DMARC alignment. Inspect headers from a received message rather than relying only on a DNS checker.

For newsletters or transactional application mail, a reputable relay can be a sensible hybrid. You can keep personal mailboxes on Stalwart while using a specialist outbound provider for high-volume or high-reputation delivery. Privacy goals and deliverability requirements do not always point to the same architecture.

Storage and backups

Mail is data. Back up the Stalwart storage volume, configuration, domain keys, and any external database or object storage used by the deployment. Encrypt backups and store them away from the mail host.

Test a restore by bringing up an isolated instance or restoring a mailbox into a test environment. A backup that has never been restored is only an assumption. Keep DKIM private keys especially protected: losing them may require DNS changes, while leaking them can undermine message signing.

Monitor disk usage, queue size, certificate expiry, authentication failures, and backup freshness. Mailboxes can grow quietly until a full disk causes delivery failures.

Privacy boundaries

Self-hosting reduces dependence on a large mailbox provider, but it does not make email private by default. Messages can be readable on recipient systems, transit may be opportunistic, and metadata such as sender, recipient, and timing is exposed to servers involved in delivery.

Use end-to-end encrypted tools for genuinely sensitive conversations. Keep the server patched, restrict administrator access, and understand where logs are stored. A privacy-first deployment is one that makes these trade-offs explicit rather than hiding them.

Upgrade and abuse prevention

Subscribe to Stalwart security announcements and upgrade deliberately. Back up first, read migration notes, and keep the previous image reference for rollback. Do not install unrelated web applications on the same public mail host unless you can isolate them well.

Configure outbound limits and watch the queue. If an account is compromised, rapid detection can prevent your IP and domain reputation from being damaged. Disable accounts that are no longer needed and rotate credentials after suspected exposure.

FAQ

Is Stalwart suitable for a personal mail server? It can be, especially for users comfortable with DNS and system administration. Start with a small deployment and test delivery before moving your primary mailbox.

Will messages always reach Gmail and Outlook? No provider can guarantee that. Correct DNS, TLS, authentication, reputation, sensible volume, and good content all affect acceptance and inbox placement.

Do I need a static IP? A stable public IP with controllable reverse DNS is strongly recommended. Residential or frequently changing addresses are usually a poor fit for direct mail delivery.

Can I use a relay with Stalwart? Yes, a relay can improve delivery for some workloads while Stalwart remains the mailbox and collaboration server. Check the current documentation for the supported relay configuration.

Is self-hosted email more private? It can reduce provider dependence and give you control over stored mail, but normal email still exposes metadata and is not automatically end-to-end encrypted.

Stalwart can be a strong foundation for a privacy-conscious mail setup, but the real project is the entire system: DNS, identity, TLS, reputation, backups, monitoring, and recovery. Build it gradually, test with a secondary domain, and only migrate important mail after the operational path is proven.