Skip to content

systemd

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

OwnMail as a systemd service

OwnMail is one binary. On a server without containers it runs as a systemd service with deploy/ownmail.service, behind a reverse proxy that serves the web interface over HTTPS.

Before you start, check outgoing port 25, the reverse DNS of the server's addresses, the firewall and the mail server's A/AAAA record as described in Docker; they are the same without Docker (ufw works here, there is no Docker to bypass it).

Install

As root, with the ownmail binary for the server's architecture (built with make build, or copied out of the image):

useradd --system --home-dir /var/lib/ownmail --shell /usr/sbin/nologin ownmail
install -m 0755 ownmail /usr/local/bin/ownmail
install -m 0644 deploy/ownmail.service /etc/systemd/system/ownmail.service
install -d -m 0750 /etc/ownmail
printf 'OWNMAIL_HOSTNAME=mail.example.com\nOWNMAIL_ACME_EMAIL=you@example.com\n' > /etc/ownmail/ownmail.env
systemctl daemon-reload && systemctl enable --now ownmail
journalctl -u ownmail | grep setup_code

Open https://mail.example.com/admin (through the reverse proxy, below) and create the first admin with the setup code.

What the unit sets

  • Data in /var/lib/ownmail (StateDirectory, mode 0700): database, secret key, mail, certificates. Back it up as a whole; without secret.key the stored DKIM keys and app passwords cannot be read.
  • Settings in /etc/ownmail/ownmail.env as OWNMAIL_<FLAG> (see the Reference); restart the service after changing it.
  • The web interface on 127.0.0.1:8080, plain HTTP, for the reverse proxy; OWNMAIL_TRUSTED_PROXIES=127.0.0.1/32,::1/128, so a proxy on the same server is believed for the visitor's address and HTTPS.
  • The mail ports (25, 465, 587, 993, 4190) on all addresses, opened as the unprivileged user ownmail through CAP_NET_BIND_SERVICE; no other capability, and the usual hardening (ProtectSystem=strict, NoNewPrivileges, a system call filter, …).
  • TimeoutStopSec=40s: OwnMail finishes running deliveries on SIGTERM.

The reverse proxy

The proxy serves HTTPS for the mail server's name and forwards everything to 127.0.0.1:8080. On port 80 it passes /.well-known/acme-challenge/ for the mail server's name on to OwnMail (except the challenges it solves itself), so OwnMail gets the certificate for the mail ports from Let's Encrypt (-tls acme, the default). It also serves autoconfig.<domain> and autodiscover.<domain> of every domain with a certificate (Thunderbird and Outlook fetch their settings there over HTTPS); Caddy gets those when a mail program first asks, after OwnMail confirmed the name (see Docker). With Caddy:

{
	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
	handle @setup {
		reverse_proxy 127.0.0.1:8080
	}
	handle {
		respond 404
	}
}

Caddy only answers the challenges it started itself and passes every other one on, so both get their certificate for the same name (see Docker). A proxy that answers every challenge itself (Traefik) cannot be used this way; then give OwnMail the proxy's certificate with OWNMAIL_TLS=files, OWNMAIL_TLS_CERT and OWNMAIL_TLS_KEY (OwnMail reads the files again when they change).

Updates and the admin password

  • Update: replace /usr/local/bin/ownmail and systemctl restart ownmail. OwnMail shows under Settings → Updates when a new version is out; it cannot replace itself here (see Updates).

  • Lost the admin password:

    sudo -u ownmail /usr/local/bin/ownmail admin reset-password -data /var/lib/ownmail you@example.com

    prints a new password, ends every session of that admin and turns their two-factor sign-in off.

Home

Running OwnMail

Using OwnMail

How it is built

Taking part

Clone this wiki locally