Mailcow packages everything a mail server needs — Postfix (SMTP), Dovecot (IMAP), Rspamd (spam filtering and DKIM signing), ClamAV, SOGo webmail with calendars and contacts, and a web admin interface — into a set of Docker containers. It is one of the most complete and maintainable ways to self-host email for a business or several domains.
Self-hosting email is rewarding but demanding: deliverability depends on your IP’s reputation, correct DNS and careful operation. Read the whole guide, including the requirements, before you start.
Requirements
Server and network
| Requirement | Why |
|---|---|
| Port 25 open outbound and inbound | Without it you cannot send or receive mail from other servers |
| Reverse DNS (PTR) you can set | Receivers reject or filter IPs without matching rDNS |
| Clean IP (not blacklisted) | Check before you start: IP blacklists |
| 2 vCPU, 6 GB RAM + swap, 20 GB+ disk (more for mail storage) | ClamAV and Rspamd need memory |
| A fresh server used only for mail | Mailcow uses many ports; avoid conflicts |
At Server.HK, US VPS meets these requirements: ports 25/465/587 are open and you can set rDNS yourself in the control panel. On other products these ports are blocked by default. Server.HK does not permit bulk, marketing or unsolicited email on any service — a mail server is for your own organisation’s normal correspondence. See the Acceptable Use Policy.
If you only need a few mailboxes and want no maintenance, a hosted email provider is usually the better choice — see email hosting.
Software
- Ubuntu 22.04/24.04 or Debian 12, freshly installed.
- Docker and the Compose plugin from Docker’s repository — install Docker.
Step 1: Hostname and DNS basics
Choose the mail server’s hostname, e.g. mail.example.com.
- Create an A record:
mail.example.com→ your server IP. - Set reverse DNS for the IP to
mail.example.com— see reverse DNS explained. - Set the system hostname:
sudo hostnamectl set-hostname mail.example.com
- Verify:
dig mail.example.com +short # your IP
dig -x YOUR_IP +short # mail.example.com.
Step 2: Install Mailcow
sudo apt update && sudo apt install -y git
cd /opt
sudo git clone https://github.com/mailcow/mailcow-dockerized
cd mailcow-dockerized
sudo ./generate_config.sh
Enter mail.example.com as the FQDN and choose your time zone. The script writes mailcow.conf. Review it — for example, if memory is tight, SKIP_CLAMD=y disables the virus scanner (saves around 1 GB of RAM).
Start everything:
sudo docker compose pull
sudo docker compose up -d
Mailcow obtains a Let’s Encrypt certificate for the hostname automatically once DNS is correct and ports 80/443 are reachable.
Step 3: Firewall
Mailcow needs these ports reachable from the internet:
| Port | Use |
|---|---|
| 25 | SMTP (server-to-server) |
| 465, 587 | Submission (mail clients sending) |
| 143, 993 | IMAP |
| 110, 995 | POP3 (optional) |
| 4190 | Sieve (filter rules, optional) |
| 80, 443 | Web interface, webmail, Let’s Encrypt |
Docker manages its own firewall rules for published ports; still make sure host firewalls or provider firewalls do not block them. Keep SSH secured separately — SSH hardening.
Step 4: First login and domain
Open https://mail.example.com/admin. Log in with the default credentials shown in the Mailcow documentation and change the admin password immediately, then enable two-factor authentication for the admin account.
Then:
- Configuration → Mail Setup → Domains → Add domain:
example.com. - Mailboxes → Add mailbox: e.g.
alice@example.com.
Step 5: DNS records for each domain
Mailcow shows the exact records needed under Domains → DNS (the blue “DNS” button next to the domain), including the DKIM key it generated. Typically:
| Name | Type | Value |
|---|---|---|
@ |
MX 10 | mail.example.com. |
@ |
TXT | v=spf1 mx -all |
dkim._domainkey |
TXT | v=DKIM1; k=rsa; p=... (from Mailcow) |
_dmarc |
TXT | v=DMARC1; p=none; rua=mailto:postmaster@example.com |
autodiscover |
CNAME | mail.example.com. |
autoconfig |
CNAME | mail.example.com. |
_autodiscover._tcp |
SRV | 0 1 443 mail.example.com. |
The DNS check page in Mailcow turns each record green when it is correct. Start DMARC at p=none, then tighten it as described in SPF, DKIM and DMARC.
Step 6: Test
- Log in to SOGo webmail at
https://mail.example.com/SOGoand send a message to a Gmail and an Outlook.com account. - In Gmail, Show original should report SPF, DKIM and DMARC: PASS.
- Reply from those accounts to confirm receiving works.
- Use a mail-tester service for a deliverability score.
- Configure phones and desktop clients — autodiscover usually fills in the settings automatically (IMAP 993, SMTP 587 with STARTTLS or 465 with TLS).
Deliverability: the ongoing part
- New IPs start with no reputation. Send normal volumes of real correspondence and avoid large mailings at first.
- Register with Microsoft SNDS and Google Postmaster Tools to see how those providers view your IP and domain.
- Watch for compromised accounts. A stolen mailbox password is the fastest way to get blacklisted. Enforce strong passwords, enable 2FA for webmail, and use Mailcow’s per-mailbox rate limits.
- Monitor blacklists regularly — checking IP blacklists.
Backups
Mailcow includes a backup script:
cd /opt/mailcow-dockerized
sudo MAILCOW_BACKUP_LOCATION=/var/backups/mailcow ./helper-scripts/backup_and_restore.sh backup all --delete-days 7
Schedule it daily with cron and copy backups off the server with restic or rsync. Test a restore on a spare server at least once.
Updates
cd /opt/mailcow-dockerized
sudo ./update.sh
Run updates regularly; the script pulls new images and applies configuration changes. Read the changelog before major updates.
Troubleshooting
| Problem | Check |
|---|---|
| Cannot receive mail | MX record, port 25 inbound, docker compose logs postfix-mailcow |
| Mail to Gmail/Outlook in spam | SPF/DKIM/DMARC pass? rDNS matches? IP reputation? Content? |
| “Relay access denied” from clients | Client not authenticating on 587/465 |
| Certificate not issued | DNS for mail.example.com, ports 80/443 open |
| High memory usage | ClamAV and Solr (full-text search); disable in mailcow.conf if needed |