Skip to content
github-actions[bot] edited this page Dec 4, 2026 · 1 revision

OwnMail with Docker

OwnMail runs on any server with Docker and the Compose plugin. The docker-compose.yml at the root of the repository starts three containers:

  • ownmail: the mail server. Its mail ports (25, 465, 587, 993, 4190) are published directly on the server; its web interface and API (port 8080, plain HTTP) are reachable only from Caddy.
  • caddy: serves the web interface over HTTPS on port 443 under the mail server's name, with a certificate from Let's Encrypt, and redirects port 80 to it.
  • updater: updates OwnMail when an administrator clicks "Update now" (see Updates). It has the Docker socket and can control Docker on the server; remove it to update by hand.

The image is ghcr.io/ownlabs-dev/ownmail: X.Y.Z, X.Y, X and latest are releases, edge follows main (see Releases), for linux/amd64 and linux/arm64.

Already running a reverse proxy? See Behind your own reverse proxy. On Coolify, see Coolify.

Before you start

A mail server depends on things outside OwnMail. Check them first; most problems with mail come from here.

Port 25 outgoing

Many hosters block outgoing connections to port 25. Without it OwnMail can receive mail but cannot deliver any.

  • Hetzner Cloud blocks ports 25 and 465 outgoing for new accounts; support unblocks them on request once the first invoice is paid.
  • AWS, Google Cloud and Azure block port 25 outgoing (AWS on request, Google Cloud permanently); DigitalOcean blocks it too.
  • Others (Vultr, OVH, netcup, …) differ by product and account age.

Test from the server:

nc -vz -w 5 gmail-smtp-in.l.google.com 25

succeeded/open is good; a timeout means it is blocked. OwnMail checks this too, in the web interface.

Reverse DNS (PTR)

Set the reverse DNS of the server's IPv4 address (and IPv6 address, if it has one) to the mail server's name, e.g. mail.example.com. This is done at the hoster (Hetzner: Server, Networking, "Reverse DNS"), not at your DNS provider. Big providers reject or junk mail from addresses whose reverse name does not match.

OwnMail delivers over IPv4 only unless OWNMAIL_IPV6_OUTBOUND=true is set; set it only when the IPv6 address has a matching reverse name too.

Firewall

Open these TCP ports inbound, in the hoster's firewall and on the server:

Port What
25 mail from other servers (required)
465 sending from mail programs over TLS
587 sending from mail programs with STARTTLS
993 reading mail with IMAP over TLS
4190 managing filters from mail programs (ManageSieve; optional)
80, 443 the web interface and the certificates

Ports published by Docker bypass ufw, so ufw alone does not close them; use the hoster's firewall to restrict access.

DNS for the mail server's name

Point the mail server's name at the server before the first start: an A record, and AAAA only when Docker passes IPv6 senders' real addresses on (see IPv6). The certificates need it.

All other records (MX, SPF, DKIM, DMARC, autoconfig, …) come later: OwnMail lists them for every domain you add, with the exact values, and checks them. OwnMail never changes DNS itself; you enter the records at your DNS provider by hand.

Start

mkdir ownmail && cd ownmail
curl -fsSLO https://raw.githubusercontent.com/ownlabs-dev/ownmail/main/docker-compose.yml
cat > .env <<'EOF'
OWNMAIL_HOSTNAME=mail.example.com
OWNMAIL_ACME_EMAIL=you@example.com
EOF
docker compose up -d

Keep the settings in .env next to the compose file: every later docker compose command (logs, pull, down) reads them from there. OWNMAIL_HOSTNAME is required: the name alone, without https://, since Caddy builds its addresses from it (OwnMail itself would take a URL too). OWNMAIL_ACME_EMAIL is optional but recommended: it is the certificate authority's contact, and only with it does Caddy fall back to ZeroSSL when Let's Encrypt cannot issue. Other settings, all optional:

Variable
OWNMAIL_IMAGE image to run, default ghcr.io/ownlabs-dev/ownmail:latest (the newest release, moved by the update container); …:X.Y.Z stays on one version, …:edge follows development (no updates offered)
OWNMAIL_SERVER_IP the server's public IPv4 (and IPv6, comma-separated) for the DNS records to enter; empty: OwnMail finds out itself
TZ time zone, default UTC
CADDY_TLS acme (default) or internal (self-signed, for tests); nothing else
OWNMAIL_TLS acme (default) or internal (self-signed, for tests); files and auto read a certificate from OWNMAIL_TLS_CERT/OWNMAIL_TLS_KEY (see Reference)

If the name did not point at the server yet when Caddy started, Caddy keeps retrying with growing pauses; once DNS is right, run docker compose restart caddy to get the certificate at once.

Every flag of ownmail serve can also be set as OWNMAIL_<FLAG> in the environment of the ownmail service (see the Reference).

The setup code

On the first start OwnMail prints a one-time setup code to its log:

docker compose logs ownmail | grep setup_code
level=WARN msg="OwnMail is not set up yet: …" setup_code=ABCD-EFGH-…

Open https://mail.example.com/admin and enter it with your e-mail address and a password to create the first admin. The code is useless once the first admin exists; until then a new one is printed on every start.

Add a domain

Add your domain and its mailboxes in the web interface, then enter the DNS records OwnMail lists for the domain at your DNS provider. A domain starts receiving mail once its MX record points to the mail server; OwnMail notices that and activates it. The mail ports open once the mail server's name, its certificate and at least one active domain are in place; until then the server status in the web interface says what is missing.

Certificates

Two certificates for the same name, both from Let's Encrypt (Caddy's with ZeroSSL as a fallback when OWNMAIL_ACME_EMAIL is set):

  • Caddy gets one for the web interface on port 443.
  • OwnMail gets its own for the mail ports (OWNMAIL_TLS=acme).

This works because Caddy answers only the ACME challenges it started itself and hands every other request below /.well-known/acme-challenge/ for the mail server's name on to OwnMail (unlike Traefik, see Coolify). Both can renew at the same time: each challenge has its own token and Caddy only answers its own.

OwnMail renews by itself and reloads the mail ports. Its certificates live in the ownmail-data volume, Caddy's in caddy-data.

Settings for mail programs

Thunderbird and Outlook fetch their settings over HTTPS from autoconfig.<domain> and autodiscover.<domain> (the recommended CNAME records of each domain point them at the mail server's name). Caddy gets a certificate for such a name the first time a mail program asks (Caddy's on-demand certificates), but only after asking OwnMail (GET /api/mail/proxy-certificate?domain=<name>) whether the name belongs to an active domain here; nobody can make it request certificates for other names pointed at the server. Those names serve only the settings for mail programs (everything else is 404). The same holds for mta-sts.<domain>, where sending servers fetch the domain's MTA-STS policy (/.well-known/mta-sts.txt, see Usage). The first request for a name waits a few seconds for the certificate. Port 80 of those names redirects to HTTPS like the mail server's name.

Port 80 of any other name passes /.well-known/acme-challenge/ on to OwnMail and redirects the rest to HTTPS. OwnMail answers only challenges for names it has set up: that is how it gets the certificate for a domain's own name for mail programs.

<domain>/.well-known/autoconfig/… (the domain's own web site) is not served by OwnMail; Thunderbird tries it as well and falls back to the names above.

How the containers are set up

  • Network. OwnMail and Caddy share the network ownmail (10.255.25.0/28 and fd0a:6f77:6e6d:6169::/64). Caddy has the fixed addresses 10.255.25.2 and fd0a:6f77:6e6d:6169::2, and OWNMAIL_TRUSTED_PROXIES names only those: OwnMail believes the visitor's address and https from Caddy and from nothing else. Port 8080 is not published. If a range clashes with a network or route on your server (ip route, e.g. a VPN or private network using 10.255.25.0/24), change it in the file at all places (the subnets with their ip_range, Caddy's addresses, OWNMAIL_TRUSTED_PROXIES).
  • Update container. updater runs ownmail updater from the same image with the Docker socket, on its own network, without ports. It can control Docker on the server; see Updates for what it does and what it refuses, or remove it to update by hand.
  • Users. OwnMail runs as user 10001 and binds the mail ports through a file capability on its binary. Caddy's image runs as root (its volumes belong to root); the file drops every capability except binding ports 80 and 443 and sets no-new-privileges.
  • Caddy's configuration is part of the compose file (configs), so there is only one file to keep. Compose does not restart Caddy when only that part changes; run docker compose up -d --force-recreate caddy after editing it.
  • HTTP/3 is off, so only TCP ports are needed. Caddy sends Strict-Transport-Security, so browsers keep to HTTPS.

IPv6

OwnMail checks each sending server's address against SPF, blocklists and its reverse name, and limits connections per address (IPv6 per /64), so it must see the real address. For IPv4, Docker keeps it on published ports. For IPv6 it depends on Docker:

  • The compose file gives its network IPv6 (enable_ipv6, a private fd0a:…/64). Docker then forwards IPv6 connections to the published ports with the sender's real address, through ip6tables. That needs Docker 27 or newer (ip6tables is on by default there); on older versions set "ip6tables": true (and "experimental": true) in /etc/docker/daemon.json and restart Docker.
  • Without that (an older Docker, ip6tables off, or a network without IPv6, as with the plain docker run below or on Coolify), Docker's userland proxy accepts IPv6 connections and passes them on over IPv4: OwnMail sees the network's gateway (an address in 10.255.25.0/28) instead of the sender. SPF is then checked against that address and fails, so mail from domains with a strict DMARC policy is refused, and all IPv6 senders share one limit.

Check it before adding the AAAA record: send a test mail to a mailbox from a host with IPv6 (e.g. swaks --to you@example.com --server mail.example.com -6) and look at the Received: line of the message: it must show the sender's IPv6 address, not 10.255.25.x. If you cannot make sure of that, leave out the AAAA record of the mail server's name; senders then use IPv4.

Testing on your own computer

Without a public name, use a name below .localhost and self-signed certificates for both containers:

printf 'OWNMAIL_HOSTNAME=mail.localhost\nCADDY_TLS=internal\nOWNMAIL_TLS=internal\n' > .env
docker compose up -d

Caddy then uses its own local authority; its root certificate is in the caddy-data volume (docker compose cp caddy:/data/caddy/pki/authorities/local/root.crt .). mail.localhost resolves to your own computer in browsers and curl. The mail ports (25, 465, …) must be free on your computer.

Data, updates, backups

  • Backups: set them up in the administration under Backups (encrypted, daily, to a Storage Box, SFTP, S3-compatible storage or a folder mounted into the container); restoring is described in Backups.

  • Everything lives in the ownmail-data volume (/data): database, secret key, mail, certificates. A copy of the volume works too; without secret.key the stored DKIM keys and app passwords cannot be read. Stop the container for a consistent copy:

    docker compose stop ownmail
    docker run --rm -v ownmail_ownmail-data:/data -v "$PWD":/backup alpine \
      tar czf /backup/ownmail-data.tar.gz -C /data .
    docker compose start ownmail

    (Compose puts the project name in front of volume names; the file sets the project name ownmail, so the volume is ownmail_ownmail-data.)

  • Updating: Settings → Updates → Update now (the update container replaces OwnMail and goes back if the new version does not start), or by hand docker compose pull && docker compose up -d. See Updates. OwnMail stops cleanly within the 40 s the file allows.

  • Lost the admin password: docker compose exec ownmail ownmail admin reset-password you@example.com.

Behind your own reverse proxy

When the server already has a reverse proxy for ports 80 and 443, run only the OwnMail container and let the proxy serve the web interface:

docker run -d --name ownmail --restart unless-stopped -v ownmail-data:/data \
  -e OWNMAIL_HOSTNAME=mail.example.com -e OWNMAIL_ACME_EMAIL=you@example.com \
  -e OWNMAIL_TRUSTED_PROXIES=172.17.0.1 \
  -p 25:25 -p 465:465 -p 587:587 -p 993:993 -p 4190:4190 -p 127.0.0.1:8080:8080 \
  ghcr.io/ownlabs-dev/ownmail:latest
docker logs ownmail 2>&1 | grep setup_code

The proxy must:

  • serve HTTPS for the mail server's name and forward everything to port 8080, setting X-Forwarded-For and X-Forwarded-Proto;
  • on port 80, pass /.well-known/acme-challenge/ for the mail server's name on to port 8080, except the challenges it is solving itself, so OwnMail can get the certificate for the mail ports. Caddy does that; Traefik does not (then copy the proxy's certificate instead, as Coolify describes, and use OWNMAIL_TLS=files).

Docker's default bridge has no IPv6, so with this variant OwnMail does not see the real address of IPv6 senders (see IPv6): leave out the AAAA record, or run it on a network with IPv6 as the compose file does.

OWNMAIL_TRUSTED_PROXIES is the address the proxy's requests come from as OwnMail sees them: with port 8080 published on 127.0.0.1 and a proxy on the host, that is the Docker bridge's gateway (172.17.0.1 on the default bridge, see docker network inspect bridge). For a proxy in a container, put both on one network instead of publishing 8080 and name the proxy's address. Without it every visitor looks like the proxy (sign-in limits count per visitor). A Caddy configuration for this (the global options block goes first in the Caddyfile; the last site serves the settings for mail programs, see above):

{
	on_demand_tls {
		ask http://127.0.0.1:8080/api/mail/proxy-certificate
	}
}
mail.example.com {
	reverse_proxy 127.0.0.1:8080
}
http://mail.example.com {
	handle /.well-known/acme-challenge/* {
		reverse_proxy 127.0.0.1:8080 {
			header_up Host {host}
		}
	}
	handle {
		redir https://{host}{uri} 308
	}
}
http:// {
	handle /.well-known/acme-challenge/* {
		reverse_proxy 127.0.0.1:8080 {
			header_up Host {host}
		}
	}
	handle {
		redir https://{host}{uri} 308
	}
}
https:// {
	tls {
		on_demand
	}
	@setup path /mail/config-v1.1.xml /.well-known/autoconfig/mail/config-v1.1.xml /autodiscover/autodiscover.xml /.well-known/mta-sts.txt
	handle @setup {
		reverse_proxy 127.0.0.1:8080
	}
	handle {
		respond 404
	}
}

Another proxy needs the same: certificates for autoconfig.<domain>, autodiscover.<domain> and mta-sts.<domain> of each domain, and those names passed on to port 8080 (at least the four paths above).

The image runs as user 10001 with its data in /data, has a health check on port 8080, and is built with docker build -t ownmail . from the repository (the web interface is built in when web/ exists). If you drop all capabilities (--cap-drop ALL), add NET_BIND_SERVICE back or the mail ports cannot be opened.

Good to know

  • Client addresses. OwnMail checks a sending server's address against blocklists and its reverse name, so it must see the real address. Docker keeps it for IPv4 on published ports. For IPv6, Docker without IPv6 enabled forwards connections through a proxy and OwnMail sees a private address (those checks are then skipped). Either enable IPv6 in Docker or leave out the AAAA record of the mail server's name.
  • Health check. The image checks http://127.0.0.1:8080/api/setup; the mail service runs in the same process and stops it when it fails.

Home

Running OwnMail

Using OwnMail

How it is built

Taking part

Clone this wiki locally