Your own mail server with Mailcow: setup from scratch
Set up Mailcow (dockerized) on your own server: Postfix, Dovecot, Rspamd and SOGo webmail under your domain – a complete mail server stack with HTTPS.
Table of contents
Your email is the backbone of your digital identity – password resets, invoices, contracts all run through it. Yet for most people it sits at a corporation in the US. With Mailcow you bring the complete mail server onto your own server: Postfix, Dovecot, spam filter and webmail, neatly packed in Docker. This tutorial gets the stack running – the tricky deliverability (SPF, DKIM, DMARC, reverse DNS) we handle afterwards in the deliverability recipe. Whether Mailcow or the lean Stalwart suits you better is settled in the direct comparison of Stalwart and Mailcow.
Running your own mail server is work – be honest with yourself
What are we building?
By the end, a complete mail server stack runs on your server, reachable as webmail at https://mail.YOUR_DOMAIN with a valid Let’s Encrypt certificate. Included are:
- Postfix as the SMTP server (send/receive),
- Dovecot for IMAP/POP3 (retrieval by mail programs),
- Rspamd as a modern spam and signature filter,
- SOGo as webmail including calendar and contacts (CalDAV/CardDAV),
- an admin interface to create domains, mailboxes and aliases.
The whole thing comes as mailcow-dockerized – a ready-bundled Compose project of 18 containers that makes the notoriously complicated mail server setup manageable. We build on Debian 13 with Docker 29.10 and Compose v5.8; mailcow is a rolling release maintained through monthly tags (you update via update.sh, there’s no classic version number). This recipe matches the 2026-11b state with Postfix 3.10.13, Dovecot 2.3.21.1, Rspamd 4.2.3 and SOGo 5.12.13.
A server of its own or next to Traefik – both work
mailcow brings its own web server and, in the default configuration, occupies ports 80/443 itself, plus the mail ports 25, 465, 587, 143, 993 and more. On a server that exists only for mailcow, that is the simplest route.
If your Traefik stack already runs there, you put mailcow behind it: Traefik takes over the web interface and the certificate, and a small extra container hands the certificate on to Postfix and Dovecot. That is step 4. mailcow marks its own guide for this as community supported. The memory appetite stays the same either way: below 6 GB of RAM it gets tight, and next to Traefik you need those on top.
Prerequisites
- A server with Debian 13 on which Docker is installed – either only for mailcow (ports 80/443 and the mail ports free) or with the Traefik from the proxy recipe on 80/443 (mail ports free, plus step 4).
- At least 6 GB RAM – the spam filter (Rspamd) and the optional virus scanner (ClamAV) need room. With less it gets sluggish or ClamAV has to go.
- A domain whose DNS you control yourself. Without matching records (especially MX and reverse DNS), no other mail server accepts your mail.
- Outbound SMTP must be open. Many providers block it by default against spam. At netcup the default policy “netcup Mail block” (ports 25/465/587) does that – you simply take it off the server in the SCP, no support ticket required. How to do that is in netcup firewall setup. Without an open port 25 you can deliver no mail to other servers.
- A PTR/reverse-DNS entry for the server IP, which you set in the provider panel (at netcup in the SCP). It must point to
mail.YOUR_DOMAIN.
Mailcow is RAM-hungry, so we recommend at least the VPS 2000. What your specific need is, the server calculator estimates for you.
VPS 2000 G12.5
8 vCores · 16 GB RAM · 256 GB SSD
from €26.92/month
For mailcow including spam and virus filter it should be 8 GB RAM.
💶 1 month free:
Single use, valid for VPS 2000 G12.5. Redeem in the cart →
💶 €5.95 voucher for new netcup customers: always valid · not for domains or VPS Lite
Step by step
Step 1: Create the DNS records
Before you install anything, set up the DNS entries – they need time to propagate, and mailcow fetches the TLS certificate for the hostname at startup. At your DNS provider (see connecting a domain to your server), create these entries. YOUR_DOMAIN is your mail domain (e.g. example.com), YOUR_SERVER_IPV4 the server’s IPv4 address:
mail.YOUR_DOMAIN. A YOUR_SERVER_IPV4
mail.YOUR_DOMAIN. AAAA YOUR_SERVER_IPV6 (if you use IPv6)
YOUR_DOMAIN. MX 10 mail.YOUR_DOMAIN.The MX record tells other mail servers: “Mail for @YOUR_DOMAIN is accepted by mail.YOUR_DOMAIN.” The hostname mail.YOUR_DOMAIN is the FQDN of the mail server – not to be confused with the mail domain itself. The further records for deliverability (SPF, DKIM, DMARC) and the PTR entry we cover in detail in the follow-up tutorial on deliverability; the PTR entry should be set already now, though, because many servers otherwise don’t accept at all.
Set the TTL of the records low before the migration (e.g. 300 seconds). Then later corrections take effect quickly while you test. After the fine-tuning you can raise them again.
Step 2: Install prerequisites on the server
Log in via SSH to the hardened server. Mailcow’s config generator needs git and jq besides Docker – the latter is easily forgotten, and the generator otherwise aborts with Cannot find command 'jq'. Install both:
sudo apt update && sudo apt install -y git jqCheck that Docker and the Compose plugin are running:
docker --version && docker compose versionYou should see two version lines – for example Docker version 29.10.1 and Docker Compose version v5.8.0. Mailcow requires at least Docker 24; below that the config generator aborts. If something’s missing, catch up on the Docker setup before continuing.
Step 3: Clone and configure Mailcow
Mailcow is delivered as a Git repository and not maintained via a single image tag. Clone it to /opt and change into it. The umask 0022 is important so the generated files get the right permissions:
sudo su
umask 0022
cd /opt
git clone https://github.com/mailcow/mailcow-dockerized
cd mailcow-dockerizedNow you generate the central configuration file mailcow.conf with the interactive generator:
./generate_config.shIt first checks whether your server’s IP is on the Spamhaus bad ASN list – a useful early warning, because hardly any mail server accepts post from some networks:
Detecting if your IP is listed on Spamhaus Bad ASN List...
Check completed! Your IP is cleanThen it asks you these questions in turn:
- Mail server hostname (FQDN): Enter
mail.YOUR_DOMAINhere – the server’s hostname, not your mail domain. The value must match the A record from step 1. - Timezone: usually already correctly pre-filled (e.g.
Europe/Berlin) – confirm with Enter. - Choose the Branch with it’s number [1/2/3]: Choose
1for themasterbranch – that’s the stable, recommended state.2isnightly(testing),3the deprecatedlegacybranch.
The generator asks about the virus scanner (Do you want to disable ClamAV now?) only if the server has at most 2.5 GiB of RAM. On a machine with 6–8 GB it quietly sets SKIP_CLAMD=n, so ClamAV runs from the start. You can switch it off any time by setting SKIP_CLAMD=y in mailcow.conf and restarting the stack.
IPv6 hosts: Docker gets restarted
If the generator finds a working IPv6 connection (default route plus a reachable peer), Docker has to speak IPv6 too – otherwise mailcow could become an open relay. If /etc/docker/daemon.json is missing, it therefore asks:
/etc/docker/daemon.json not found. Create it with IPv6 settings? [Y/n]Confirm with Enter and it creates the file itself (on Docker ≥ 28 {"ipv6": true} is enough) and restarts Docker right away. If anything else already runs on the server, that restart takes every container down with it – Traefik included, so the services behind it are gone for a few seconds. Answer n and the generator aborts, leaving you to add the setting by hand. If you deliberately want to run without IPv6, set ENABLE_IPV6=false in mailcow.conf later.
Afterwards take a look at the generated mailcow.conf. The most important values are at the top:
grep -E "^(MAILCOW_HOSTNAME|TZ|HTTP_PORT|HTTPS_PORT|SKIP_CLAMD|ENABLE_IPV6)=" mailcow.confOn a server with 8 GB of RAM it looks like this – SKIP_CLAMD=n means “ClamAV is running”:
MAILCOW_HOSTNAME=mail.YOUR_DOMAIN
HTTP_PORT=80
HTTPS_PORT=443
TZ=Europe/Berlin
SKIP_CLAMD=n
ENABLE_IPV6=trueThe file also contains all port assignments. In the standard configuration mailcow claims these host ports:
25 SMTP (server-to-server delivery)
465 SMTPS (send with implicit TLS)
587 Submission (send by mail programs, STARTTLS)
143 IMAP / 993 IMAPS (retrieval by mail programs)
110 POP3 / 995 POP3S
4190 Sieve (server-side filter rules)
80 HTTP / 443 HTTPS (webmail + admin + ACME)These ports must be free on the host. If a reverse proxy already runs on 80/443 there, you rebind mailcow’s nginx in the next step; the mail ports sit directly on the host in that case too.
Step 4: Only next to Traefik – put mailcow behind the proxy
If the server is there only for mailcow, skip this step. If Traefik from the proxy recipe already runs there – network proxy, certificate resolver le, acme.json under /opt/traefik/ – you need two files: one changed, one new. Traefik itself stays untouched.
The mailcow.conf. All seven keys are already in the file; you only change their values:
HTTP_PORT=8080
HTTP_BIND=127.0.0.1
HTTPS_PORT=8443
HTTPS_BIND=127.0.0.1
HTTP_REDIRECT=n
SKIP_LETS_ENCRYPT=y
AUTODISCOVER_SAN=nThe four bind lines take mailcow’s nginx off 80/443 and attach it to 127.0.0.1 – it is no longer reachable from outside, and Traefik talks to it directly inside the Docker network. SKIP_LETS_ENCRYPT=y switches off mailcow’s own ACME client, and AUTODISCOVER_SAN=n belongs to it.
HTTP_REDIRECT=n is missing from mailcow’s own guide, and nothing works without it: the generator sets the switch to y, and nginx then redirects every request to HTTPS. Traefik, however, passes requests on unencrypted to port 8080 – every answer is the same redirect again, and the browser goes round in circles. Traefik handles the redirect from HTTP to HTTPS anyway.
The docker-compose.override.yml. Put it next to mailcow’s docker-compose.yml; Compose reads it automatically. It is listed in mailcow’s .gitignore, so update.sh leaves it alone:
# /opt/mailcow-dockerized/docker-compose.override.yml
services:
nginx-mailcow:
networks:
proxy:
labels:
- traefik.enable=true
- traefik.docker.network=proxy
- traefik.http.services.mailcow.loadbalancer.server.port=8080
- traefik.http.routers.mailcow.rule=Host(`mail.YOUR_DOMAIN`)
- traefik.http.routers.mailcow.entrypoints=websecure
- traefik.http.routers.mailcow.tls.certresolver=le
- traefik.http.routers.mailcow.middlewares=mailcow-only-me
- traefik.http.middlewares.mailcow-only-me.ipallowlist.sourcerange=YOUR_IPV4/32,YOUR_IPV6_PREFIX::/64
- traefik.http.routers.mailcow.service=mailcow
- traefik.http.routers.mailcow-autoconfig.rule=Host(`autoconfig.YOUR_DOMAIN`) && Path(`/mail/config-v1.1.xml`)
- traefik.http.routers.mailcow-autoconfig.entrypoints=websecure
- traefik.http.routers.mailcow-autoconfig.tls.certresolver=le
- traefik.http.routers.mailcow-autoconfig.service=mailcow
- traefik.http.routers.mailcow-autodiscover.rule=Host(`autodiscover.YOUR_DOMAIN`) && Path(`/autodiscover/autodiscover.xml`)
- traefik.http.routers.mailcow-autodiscover.entrypoints=websecure
- traefik.http.routers.mailcow-autodiscover.tls.certresolver=le
- traefik.http.routers.mailcow-autodiscover.service=mailcow
certdumper:
image: ghcr.io/kereis/traefik-certs-dumper:1.8.34
restart: unless-stopped
network_mode: none
command: --restart-containers mailcowdockerized-postfix-mailcow-1,mailcowdockerized-dovecot-mailcow-1
environment:
DOMAIN: mail.YOUR_DOMAIN
volumes:
- /opt/traefik/:/traefik:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data/assets/ssl:/output:rw
networks:
proxy:
external: trueThe upper part adds mailcow’s nginx to the proxy network as well and gives Traefik three routers: the interface under mail.YOUR_DOMAIN and the two addresses mail programs use to find their settings on their own. For autoconfig.YOUR_DOMAIN and autodiscover.YOUR_DOMAIN you then need two more DNS records, most simply as a CNAME to mail.YOUR_DOMAIN – without them Traefik gets no certificate for those names.
mailcow-only-me lets only your own address through until you have changed the default password; everyone else gets 403 Forbidden. As long as the default password applies, the instance otherwise belongs to whoever opens the page first – and scanners sometimes find new hostnames through the public certificate logs within seconds of the start. Look up your addresses on your own computer, not on the server: curl -4 -s https://ifconfig.me for IPv4, curl -6 -s https://ifconfig.me for IPv6 (take the first four blocks of it). If you have no IPv6, drop the second entry including the comma – but only then: browsers prefer IPv6, and an IPv4-only list locks you out. More on this in Hardening Traefik. The lock only sits on the interface router; the two autoconfig routers serve nothing but their XML file anyway.
The lower part is the certificate dumper. Postfix and Dovecot speak TLS themselves and never see Traefik’s certificate. The dumper reads it from Traefik’s acme.json and writes cert.pem and key.pem for mail.YOUR_DOMAIN into data/assets/ssl – exactly where mailcow expects them. Because Postfix and Dovecot read their certificate only at startup, it restarts both as soon as the certificate changes. Three details:
- The container names
mailcowdockerized-…-1follow fromCOMPOSE_PROJECT_NAMEinmailcow.conf. mailcow’s guide still uses the names from the old Compose v1 (mailcow_postfix-mailcow_1); with those, the dumper finds nothing to restart. - What you mount is the directory
/opt/traefik/that holdsacme.json. If the path points elsewhere, the dumper only reports/traefik/acme.json is not a file. Retrying.... - It needs the Docker socket for the restarts, but no network (
network_mode: none).
mailcow trusts Traefik out of the box: the Docker networks 172.16.0.0/12 and fc00::/7 are listed as trusted proxies in its nginx configuration. mailcow’s logs therefore show the visitor’s real address and not Traefik’s – which matters, because mailcow bans addresses after failed logins and would otherwise lock out the proxy itself.
Step 5: Open the firewall
Your UFW firewall must let the mail and web ports through. Besides SSH, you allow:
sudo ufw allow 25/tcp
sudo ufw allow 80,443/tcp
sudo ufw allow 465,587/tcp
sudo ufw allow 143,993/tcp
sudo ufw allow 110,995/tcp
sudo ufw allow 4190/tcpIf you additionally use the netcup firewall in the SCP, allow the same ports there too, otherwise the perimeter firewall blocks the traffic before it reaches the server. Add two rules there for the replies of the Rspamd fuzzy servers (UDP with source port 11445 and 11335), because the netcup firewall does not let UDP replies through on its own. The ready-made table is in the mail server section of the firewall tutorial.
Step 6: Start the stack
Now you download the images and start the stack. Expect a little over 4.5 GB on disk – the stack consists of 18 services, the biggest being SOGo, Dovecot and Postfix:
docker compose pull
docker compose up -dThe first boot takes a few minutes – the database, search index and the individual services initialize. Watch the progress with:
docker compose psThe STATUS column shows Up … for every service; the containers with their own health check (such as unbound-mailcow and clamd-mailcow) additionally report (healthy). During this time, mailcow fetches the Let’s Encrypt certificate for mail.YOUR_DOMAIN in the background via its built-in ACME client. For that, the A record and port 80 must be reachable from outside – if that’s not the case, the acme-mailcow container stays in a retry loop and you see it in its logs (docker compose logs acme-mailcow).
Behind Traefik (step 4), the certdumper runs as a nineteenth container, and the certificate comes from Traefik. Whether Postfix and Dovecot really serve it, you check on the server directly at the IMAP port:
echo | openssl s_client -connect 127.0.0.1:993 2>/dev/null | openssl x509 -noout -subject -issuersubject=CN=mail.YOUR_DOMAIN
issuer=C=US, O=Let's Encrypt, CN=YR2Let’s Encrypt rotates the last part of the issuer (YR1, YR2 …); what matters is Let's Encrypt and your hostname. The same goes for 465, 587 and 143 – for the last two with -starttls smtp and -starttls imap.
Step 7: First login to the admin interface
Open https://mail.YOUR_DOMAIN in the browser. You land in the mailcow UI. Log in with the default credentials:
User: admin
Password: moohooIf the form shows “User Login”, click “Log in as admin” at the bottom – the login form on the home page otherwise logs you in as a mailbox user, not as an administrator.
Change the default password immediately
admin / moohoo is publicly known. Change the admin password immediately under System → Configuration → Access: in the Edit administrator details section, click Edit next to the admin user. In the same tab, enable two-factor authentication (TOTP or WebAuthn) right away. As long as the default password applies, your mail server is wide open like a barn door. Behind Traefik, the lock from step 4 keeps strangers out until then; without Traefik, only speed protects you.After logging in you land in the mailcow dashboard with the overview of your services:

If mailcow runs behind Traefik and the default password is changed, take the lock back out – mail.YOUR_DOMAIN also carries webmail, calendars, contacts and ActiveSync for your mail programs: delete the two lines containing mailcow-only-me from docker-compose.override.yml and apply the change:
docker compose up -dStep 8: Create a mail domain and first mailbox
In mailcow you separate domain (e.g. example.com) and mailbox (e.g. contact@example.com).
Via E-Mail → Configuration in the top navigation bar you manage domains and mailboxes in separate tabs:

On the Domains tab, click Add domain and enter your domain
YOUR_DOMAIN. The default values (mailbox and alias quotas) are fine for the start. Save with “Add domain and restart SOGo” at the bottom – not with “Add domain only”. Why, see the box below.
Create a new mail domain. Open the Mailboxes tab – it’s a drop-down – and its Mailboxes entry, then click Add mailbox – username, domain, full name and a strong password (password manager!). This mailbox can then log in to the webmail and via IMAP/SMTP.

Create a new mailbox.
Without a SOGo restart the webmail stays shut
No authentication sources defined - nobody will be able to login, and every webmail login ends on a bare Unauthorized page – even though password and mailbox are correct. Hence the second button; after the fact you get there via E-Mail → Restart SOGo. If a failed login has already been cached, restarting memcached as well helps (see “When things go wrong”).After creating the domain, mailcow shows you the DKIM key and the recommended DNS records under the domain entry. You need those for deliverability – more on that shortly.
Step 9: Test the webmail
Open https://mail.YOUR_DOMAIN/SOGo/ (or click Apps → Webmail at the top right in the mailcow UI). If you aren’t signed in yet, you first land on the mailcow “User Login” mask – log in there with your full mail address and the mailbox password and you are passed straight through to the SOGo webmailer with inbox, calendar and contacts. A test mail from you to yourself should be in the inbox immediately – that proves that local delivery, IMAP and webmail work.
The real acid test, however, is sending to the outside and receiving from the outside – and that’s exactly where it’s decided whether your mails land in the recipient’s inbox or spam folder. That depends on SPF, DKIM, DMARC and the PTR entry and is substantial enough for its own recipe.
Note
When things go wrong
The page answers with 403 Forbidden (behind Traefik only). The lock from step 4 does not let your address through. Usually the IPv6 is missing or has changed – look up both addresses again (see there), correct sourcerange and restart with docker compose up -d.
The interface only shows Fatal error: … Failed opening required '/web/inc/app_info.inc.php'. The generator ran without umask 0022, for example after a fresh SSH login or on a server whose default umask is stricter (027 after a Lynis hardening, say). The file then gets mode 640, and PHP inside the container can’t read it. chmod 644 data/web/inc/app_info.inc.php brings the page back immediately; the cleaner fix is to delete the folder and repeat step 3 in one session with umask 0022, so no other file is affected.
generate_config.sh aborts with Cannot find command 'jq'. The jq package is missing. sudo apt install -y jq and start the generator again.
The generator reports “User declined to create daemon.json” and aborts. On hosts with active
IPv6 you answered the question about the IPv6-capable Docker configuration with n – without it
mailcow won’t run there, and an open relay looms. Create /etc/docker/daemon.json containing
{"ipv6": true} (Docker 28 and newer), restart Docker with sudo systemctl restart docker and run
./generate_config.sh again – or simply confirm the question with Enter on the second attempt, then
the generator does both itself.
The webmail only answers Unauthorized. SOGo doesn’t know your mail domain: it reads the domain
list exclusively at startup and wasn’t restarted after the domain was created – its logs say No authentication sources defined - nobody will be able to login. Restart SOGo via E-Mail → Restart
SOGo. If that doesn’t help, a failed login is still stuck in the cache: docker compose restart memcached-mailcow sogo-mailcow.
No certificate, acme-mailcow keeps restarting (only without Traefik). Let’s Encrypt can’t reach your server on port
80, or the A record of mail.YOUR_DOMAIN is wrong. Check with docker compose logs acme-mailcow
whether the hostname and IP match, and that port 80 is open through UFW and the netcup firewall.
Mails to the outside aren’t delivered, logs show timeouts on port 25. Your provider blocks outbound SMTP traffic (common as spam protection). At netcup it’s the default policy “netcup Mail block” (ports 25/465/587): in the SCP under Firewall → Policies, take that netcup template off the server – no support ticket needed, details in netcup firewall setup. Without it you can’t send mail to other servers – receiving and local delivery still work.
Ports 80/443 can’t be bound (address already in use). A web server or reverse proxy (e.g.
Traefik) already runs on the host. Either mailcow gets a server of its own, or you put it behind the
proxy as in step 4. The mail ports sit directly on the host either way.
Behind Traefik the interface doesn’t load, the browser reports too many redirects. mailcow.conf
still says HTTP_REDIRECT=y. mailcow’s nginx then redirects even the requests Traefik passes on
unencrypted to HTTPS – in a circle. Set HTTP_REDIRECT=n and run docker compose up -d.
Behind Traefik, mail programs show a self-signed certificate. The dumper wrote nothing or didn’t
restart Postfix and Dovecot. docker compose logs certdumper tells you why: acme.json is not a file means a wrong path to Traefik’s directory. If there is no Restarting container … was successful, the names in --restart-containers are wrong – compare them with
docker compose ps --format '{{.Name}}'.
Containers start slowly or are killed by the kernel (OOM). Too little RAM. Go to at least 6–8 GB
or disable ClamAV in mailcow.conf (SKIP_CLAMD=y) – the virus scanner is the biggest memory
eater.
Your problem is not listed? Search all error messages →
Maintenance & backups
A mail server lives off maintenance – plan it firmly.
Updates. Mailcow brings its own update script. Run it regularly (about monthly); it updates the Compose file and all images to the latest state:
cd /opt/mailcow-dockerized
sudo ./update.shAfter a confirmation prompt, the script records your changes to mailcow’s own files in a Git commit (“Before update on …”), stops all containers, fetches the new state including the images and restarts the stack – expect one to two minutes in which no mail is accepted. mailcow.conf and a docker-compose.override.yml are in mailcow’s .gitignore; the script leaves them alone, but doesn’t back them up either. Read the release notes shown – on bigger jumps, manual steps are occasionally listed there.
Backups. Your mails, the database and the crypto keys (DKIM!) live in Docker volumes. Mailcow brings a ready-made backup script for this:
sudo install -d -m 755 /opt/mailcow-backups
cd /opt/mailcow-dockerized/helper-scripts
sudo BACKUP_LOCATION=/opt/mailcow-backups ./backup_and_restore.sh backup allThe target directory has to exist beforehand. If it is missing, the script asks
Create it now? [y|N]; without a terminal, as in a cron job, that counts as no, and it exits without a backup. It also requires that others may read the folder (mode 755), otherwise it aborts with is not write-able for others. Hence install -d -m 755 instead of mkdir: on a hardened server with umask 027, mkdir creates the folder with 750.
If mailcow runs behind Traefik, the docker-compose.override.yml belongs in the backup as well – the script only saves mailcow.conf. Then back up the target directory away from the server – cleanest encrypted with Restic. Especially important are the DKIM keys: if they’re lost, your signatures break after a restore until you reset the DNS records. A backup you’ve never restored is just a hopeful guess – test the restoration once on a test system.
Keep an eye on reputation. Occasionally check whether your server IP has landed on a block list (e.g. via one of the common block-list checkers) and take a look at the Rspamd dashboard in the mailcow UI now and then. A hacked or misconfigured mailbox that sends spam quickly ruins the reputation of your entire domain.
Send feedback: feedback@serverkueche.de
What's next?


You might also like

