Skip to content

Coolify

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

OwnMail on Coolify

Coolify is one way to run OwnMail; without it, see Docker or systemd. On Coolify OwnMail runs as one Docker Compose resource. Its mail ports (25, 465, 587, 993, 4190) are published directly on the server; its web interface and API (port 8080, plain HTTP) are served by Coolify's proxy under the mail server's name, for example https://mail.example.com.

Which proxy does your server run?

In Coolify, open Servers, the server, then Proxy. It shows Traefik (Coolify's default) or Caddy. The two need different files, because they treat the certificate challenges of other programs differently (see Certificates):

Proxy File Certificate of the mail ports
Traefik deploy/coolify/docker-compose.yml copied from Traefik by the certs helper (OWNMAIL_TLS=files)
Caddy deploy/coolify/docker-compose.caddy.yml OwnMail's own, from Let's Encrypt (OWNMAIL_TLS=acme)

With Traefik the resource has two services: ownmail and certs, a small helper that copies the certificate Traefik holds for the mail server's name into a volume, so the mail ports use the same certificate as the web interface. With Caddy it is ownmail alone.

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

Before you start

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

Port 25 outgoing

Many hosters block outgoing connections to port 25 to stop spam from compromised servers. Without it OwnMail can receive mail but cannot deliver any to other servers.

  • Hetzner Cloud blocks ports 25 and 465 outgoing for new accounts; you can ask support to unblock them 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, not from your computer:

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

succeeded/open is good; a timeout means the hoster (or a firewall) blocks it. OwnMail also checks this itself (POST /api/mail/checks/outbound, and 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 outgoing mail 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 (e.g. a Hetzner Cloud 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 Coolify's proxy: web interface and certificates (already open for Coolify)

Ports published by Docker bypass ufw on the server, 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 you deploy with an A record: the proxy needs it to get the certificate. Leave out the AAAA record on Coolify (see Client addresses).

Everything else (MX, SPF, DKIM, DMARC, autoconfig, …) comes later: OwnMail lists the records to enter for each domain you add, with the exact values, and checks them. OwnMail never changes DNS itself; you enter the records at your DNS provider. A domain starts receiving mail once its MX record points to the mail server (OwnMail notices that and activates the domain).

Deploy

  1. In Coolify: New Resource, then Docker Compose from this repository with the compose file location /deploy/coolify/docker-compose.yml (Traefik) or /deploy/coolify/docker-compose.caddy.yml (Caddy), or Empty and paste the file.

  2. Environment Variables:

    Variable
    OWNMAIL_HOSTNAME the mail server's name, e.g. mail.example.com (required; the domain as Coolify shows it, https://mail.example.com, works too)
    OWNMAIL_ACME_EMAIL contact for Let's Encrypt (Caddy variant only; optional)
    OWNMAIL_SERVER_IP the server's public IPv4 (and IPv6, comma-separated) for the DNS records to enter; empty: OwnMail asks the internet
    OWNMAIL_IMAGE image to run, default ghcr.io/ownlabs-dev/ownmail:latest (the newest release, so a redeploy updates); …:X.Y.Z stays on one version
    TZ time zone, default UTC

    The other variables in the file have defaults that fit Coolify (see below).

  3. Domains: set the domain of the ownmail service to https://mail.example.com, the same name as OWNMAIL_HOSTNAME. The file already tells Coolify to route it to port 8080 (SERVICE_FQDN_OWNMAIL_8080).

  4. Deploy.

The setup code

On the first start OwnMail prints a one-time setup code to its log. Open the resource in Coolify, then Logs of the ownmail container, and look for

level=WARN msg="OwnMail is not set up yet: …" setup_code=ABCD-EFGH-…

(or on the server: docker logs <ownmail container> 2>&1 | grep setup_code). Open https://mail.example.com/admin and enter it with your e-mail address and a password to create the first admin; without the web interface built in, use the API:

curl -c jar -X POST https://mail.example.com/api/setup \
  -d '{"code":"ABCD-EFGH-…","email":"you@example.com","password":"…"}'

The code is useless once the first admin exists. A new code is printed on every start until then.

Add a domain

Add your domain, create mailboxes and enter the DNS records OwnMail lists for the domain at your DNS provider (web interface, or GET /api/mail/domains/<domain>/records). The mail ports open once the mail server's name, its certificate and at least one active domain are in place; until then OwnMail's status (GET /api/mail/status) says what is missing.

Certificates

The mail ports need a certificate for the mail server's name.

With Caddy

Caddy answers only the ACME challenges it started itself; every other request below /.well-known/acme-challenge/ goes through its routes like any other request. Coolify's Caddy redirects port 80 to HTTPS for the site, Let's Encrypt follows that redirect (without checking the certificate on 443), and on 443 Caddy again answers only its own challenges and forwards the rest to OwnMail. So OwnMail gets its own certificate with OWNMAIL_TLS=acme and no helper is needed. (In Caddy's source, HandleHTTPChallenge runs first for every request on every port and only claims a challenge whose token it started; tested with a local ACME server: the challenge went 80 → redirect → 443 → OwnMail.)

The redirect needs Caddy's own certificate on 443 first. Right after the first deploy OwnMail may ask before Caddy has it; that attempt fails and OwnMail waits 10 minutes before the next (longer after more failures). Once https://mail.example.com opens, restart the ownmail container to try at once.

With Traefik

On Coolify's default proxy the certificate comes from Traefik:

  • Traefik gets a certificate for mail.example.com anyway, because the web interface is served under that name.
  • Traefik (v3, which Coolify uses) answers every ACME HTTP-01 challenge on port 80 itself, whichever router would match, and never passes /.well-known/acme-challenge/ on to a container. OwnMail's own ACME client (OWNMAIL_TLS=acme) therefore cannot get a certificate through Coolify's proxy.
  • So the compose file runs OwnMail with OWNMAIL_TLS=files, and the certs service copies Traefik's certificate and key for OWNMAIL_HOSTNAME from Traefik's store (/data/coolify/proxy/acme.json, mounted read-only) into the ownmail-certs volume, looking again every 5 minutes. OwnMail reads the files again when they change, so Traefik's renewals reach the mail ports by themselves.

The helper copies only what it has checked: certificate and key must be PEM, parse, belong together, name OWNMAIL_HOSTNAME and not have expired. Of several entries it takes the one whose main name is the mail server's name and that ends last; one that only lists it as an additional name (SAN) is used only when there is none. Wildcard certificates (*.example.com) are not used. When nothing usable is there, it logs why and leaves the files as they are, so a broken entry never replaces a good certificate. deploy/coolify/traefik-certs_test.sh tests this against the image with broken and good stores.

The certs service runs as root because Traefik's store is readable only by root. It contains the keys of every site on the server, so the service is locked down: no capability except CHOWN (to hand the files to OwnMail's user), no network (network_mode: none), a read-only file system and no-new-privileges; it writes nothing but the mail server's certificate and key. Its health check turns healthy once the certificate is there; right after the first deploy Traefik may need a minute to get it. The store is mounted with create_host_path: false: if it is not where TRAEFIK_ACME_JSON says, the deploy fails instead of mounting an empty directory. Should your Coolify version refuse network_mode: none, remove that line; the service never uses the network.

If Coolify's proxy keeps its data elsewhere, set TRAEFIK_ACME_JSON to the path of acme.json on the server.

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), and sending servers fetch a domain's MTA-STS policy from mta-sts.<domain>. Coolify's proxy serves and gets certificates only for the names set as the service's domains, so add those three names of each mail domain there, after the mail server's name, and redeploy:

https://mail.example.com,https://autoconfig.example.com,https://autodiscover.example.com,https://mta-sts.example.com

The proxy (Traefik or Caddy) then gets a certificate for each name once its CNAME points here, and passes them on to OwnMail, which answers only the settings for mail programs under them (the web interface still works under those names, but nobody needs it there). The certs service keeps taking the certificate whose main name is the mail server's name. Without these names Thunderbird and Outlook may not find the settings by themselves and ask for them; the settings in Connect a device always work.

A domain's own name for mail programs is added the same way. Behind Coolify's Caddy, OwnMail then gets its certificate through the proxy like the mail server's. Behind Traefik it cannot (Traefik answers every challenge itself, and the certs service copies only the mail server's certificate), so mail programs keep using the mail server's name.

Other ways

  • OWNMAIL_TLS=acme with Traefik works only where port 80 of the mail server's name reaches OwnMail's port 8080 unchanged. On Coolify that needs --entrypoints.http.allowACMEBypass=true in the proxy's configuration, which lowers the priority of Traefik's own challenge router for every site on the server; sites whose HTTP router redirects to HTTPS can then fail to renew their certificates. Not recommended on a shared Coolify server. Set OWNMAIL_ACME_EMAIL with it and remove the certs service.
  • OWNMAIL_TLS=files with your own certificate: mount it and set OWNMAIL_TLS_CERT/OWNMAIL_TLS_KEY; remove the certs service.
  • OWNMAIL_TLS=auto uses the files while they are there and valid, and gets OwnMail's own certificate from Let's Encrypt otherwise. It helps where something else provides the files only sometimes; it does not let the Traefik file work behind Caddy (the certs service needs Traefik's store) and gives nothing behind Traefik (whose own challenge handling keeps Let's Encrypt from reaching OwnMail, see above).
  • OWNMAIL_TLS=internal makes a self-signed certificate; for tests only, mail programs and other servers will warn or refuse.

What the defaults do

Variable Default
OWNMAIL_TLS files (Traefik), acme (Caddy) see Certificates
OWNMAIL_TRUSTED_PROXIES private address ranges whose X-Forwarded-For/X-Forwarded-Proto are believed. Port 8080 is not published, so only containers on Docker's networks (Coolify's proxy) reach it; their headers tell OwnMail the visitor's real address (sign-in limits, activity). Coolify connects its proxy to the resource's own network, so the ranges of Docker's networks are the default. Narrow it to the proxy's addresses (docker inspect coolify-proxy, one per network) if other containers you do not trust share those networks.
OWNMAIL_SERVER_IP empty addresses for the DNS records; set it when the server has several or sits behind NAT
CERTS_INTERVAL 300 seconds between looks of the certs service (Traefik)

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

Data, updates, backups

  • Backups: set them up in the administration under Backups (encrypted, daily, to a Storage Box, SFTP or S3-compatible storage); restoring is described in Backups.
  • Everything lives in the ownmail-data volume (/data): database, secret key, mail, certificates for internal/acme. A copy of the volume works too; without secret.key the stored DKIM keys and app passwords cannot be read. Coolify's volume backups or docker run --rm -v <volume>:/data … with tar both work; stop the container for a consistent copy.
  • Updating: OwnMail shows when a new version is out. Enter the resource's deploy webhook and an API token with the permission "deploy" under Settings → Updates (way "Deploy hook"), then Update now redeploys from there; see Updates. Or redeploy in Coolify yourself: with latest it pulls the newest release; with an exact version, change OWNMAIL_IMAGE. OwnMail stops cleanly on SIGTERM within the 40 s the compose file allows.
  • Lost the admin password: in Coolify's terminal for the ownmail container (or docker exec), run ownmail admin reset-password you@example.com.

Good to know

  • Client addresses. OwnMail checks the sending server's address against SPF, blocklists and its reverse name, and limits connections per address (IPv6 per /64); it must see the real address. Docker keeps it for IPv4 on published ports. Coolify's networks normally have no IPv6, so Docker forwards IPv6 connections through a proxy and OwnMail sees the network's IPv4 gateway instead: 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. So on Coolify leave out the AAAA record of the mail server's name; senders then use IPv4. (The root docker-compose.yml gives its network IPv6 and keeps the real address, see Docker.)
  • Capabilities. The image runs as user 10001 and binds the low mail ports through a file capability (cap_net_bind_service) on the binary. If you drop all capabilities (cap_drop: [ALL]), add NET_BIND_SERVICE back (cap_add: [NET_BIND_SERVICE]) or the binary will not start ("operation not permitted").
  • Health check. The image's health check asks http://127.0.0.1:8080/api/setup; the mail service runs in the same process and stops it when it fails.
  • Without Coolify. Use the docker-compose.yml at the root of the repository (Docker): it brings Caddy as the reverse proxy, which passes OwnMail's certificate challenges on, so OwnMail gets its own certificate (OWNMAIL_TLS=acme) and needs no certs helper.

Home

Running OwnMail

Using OwnMail

How it is built

Taking part

Clone this wiki locally