
Corporate mail, part 4: your own mail server on Ubuntu 24.04 — Mailcow, antispam, and backups
🌐 Machine-translated from Russian. Show original
In this part:
- Why not assemble "Postfix + Dovecot" by hand
- Requirements
- Step 1. Preparing Ubuntu 24.04
- Step 2. Docker from the official repository
- Step 3. Installing Mailcow
- Step 4. Domain, mailboxes, and DKIM
- Step 6. Clients
- Step 7. Backups
- Step 8. Updates and monitoring
- When your own server is a bad idea
- Checklist of your server
Why not assemble "Postfix + Dovecot" by hand#
A classic mail server consists of about a dozen components: Postfix (SMTP), Dovecot (IMAP), antispam, antivirus, DKIM signature, webmail, control panel, certificates. You can build them manually, but each update turns into a quest. For a company, it's better to use a supported build where everything is updated by a single command.
| Build | What is it | Who |
|---|---|---|
| Mailcow (dockerized) | Postfix, Dovecot, Rspamd, ClamAV, SOGo (webmail, calendars, contacts), web panel — in Docker | company from 5 to hundreds of mailboxes; the main version of this article |
| Stalwart | one modern Rust server: SMTP, IMAP, POP3, JMAP, CalDAV/CardDAV; AGPL-3.0, some features — in the Enterprise version | those who want fewer components and are ready for a younger |
| Mail-in-a-Box | an all-in-one script for a single domain on pure Ubuntu | small teams and personal projects |
Mailcow releases updates monthly (releases are named by date, e.g., 2026-11) and has detailed documentation: docs.mailcow.email.
Requirements#
| Resource | Minimum according to Mailcow | documentation
| --- | --- |
| Memory | 6 GiB + 1 GiB swap; 8 GiB is recommended for 5–10 users |
| Processor | 1 GHz, x86_64 or ARM64 |
| Disk | 20 GiB without emails + extra mail capacity; better SSD |
| OS | Ubuntu 22.04 and newer (compatible with 24.04 LTS), Debian 11–13, AlmaLinux/Rocky |
| Virtualization | KVM, ESXi, Hyper-V — yes; OpenVZ, Virtuozzo, LXC — no; NAS (Synology, QNAP) — no |
If there is little memory, you can disable antivirus and full-text search in mailcow.conf: SKIP_CLAMD=y, SKIP_FTS=y.
The network is more important than hardware:
- static white IP not blacklisted (check on MXToolbox before ordering);
- PTR for this IP →
mail.company.kz(configurable provider); - Open outgoing port 25. Many VPS providers block it by default — check in advance and ask to open;
- incoming ports: 25, 465, 587 (SMTP), 143, 993 (IMAP), 110, 995 (POP3, if needed), 4190 (Sieve), 80, and 443 (web and Let's Encrypt certificates).
If you need data in Kazakhstan, place the server in a data center in the Republic of Kazakhstan (see the "Clouds in Kazakhstan" series).
Step 1. Preparing Ubuntu 24.04#
sudo hostnamectl set-hostname mail.company.kz
sudo apt update && sudo apt full-upgrade -y
sudo apt install -y git openssl curl gawk coreutils grep jq
timedatectl # время должно быть синхронизировано (NTP active: yes)
DNS records before installation: A mail.company.kz → 203.0.113.25, MX company.kz → mail.company.kz, CNAME autodiscover , and autoconfig → mail.company.kz. Rest (SPF, DKIM, DMARC) — after installation.
Step 2. Docker from the official repository#
Mailcow requires Docker 24+ and Docker Compose v2. The docker.io package from the Ubuntu repository is not suitable — install from the Docker repository:
curl -sSL https://get.docker.com | sudo CHANNEL=stable sh
sudo systemctl enable --now docker
docker version && docker compose version
⚠️ Mailcow documentation warns: ufw and firewalld on a Docker host can break the container network. The recommended option is to restrict access on an external firewall (hosting or router) or via the iptables chain
DOCKER-USER. Do not set ufw "out of habit" like on a regular server.
More about Docker — the series "Docker and CI/CD from Scratch."
Step 3. Installing Mailcow#
sudo -i
umask 0022
cd /opt
git clone https://github.com/mailcow/mailcow-dockerized
cd mailcow-dockerized
./generate_config.sh # спросит FQDN: mail.company.kz, часовой пояс: Asia/Almaty
nano mailcow.conf # при необходимости: SKIP_CLAMD, SKIP_FTS, порты
docker compose pull
docker compose up -d
After a few minutes, open https://mail.company.kz/admin. Default login is admin, password is moohoo: change it immediately and enable two-factor login for the administrator (TOTP or WebAuthn key).
Let's Encrypt Mailcow receives the certificate automatically if port 80 is available from the internet and DNS already points to the server.
Step 4. Domain, mailboxes, and DKIM#
- Mail settings section of the → Domains panel → Add domain:
company.kz, mailbox limits, and quotas. - Mailboxes → Add mailbox: users. Passwords are long, send them through a password manager, not in a messenger.
- ARC/DKIM keys section: generate a 2048-bit key for the domain → copy TXT to DNS (
dkim._domainkey.company.kz). - Add SPF and DMARC for part 2: Corporate mail, part 2: domain and DNS — MX, SPF, DKIM, DMARC, PTR, MTA-STS, and deliverability verification.
Additionally, it is worth prohibiting dangerous attachments (.exe, .js, .vbs, .iso, Office macros from external emails) — most phishing attacks proceed this way.
Step 6. Clients#
- SOGo webmail:
https://mail.company.kz/SOGo— mail, calendars, contacts. - Outlook / Thunderbird / mail on the phone — IMAP 993 and SMTP 587 (or 465), auto-configuration via autodiscover/autoconfig.
- Calendars and contacts on phones — CalDAV/CardDAV, via the app or profile from SOGo.
Step 7. Backups#
Included — Mailcow volume backup script (emails, databases, settings, DKIM keys):
cd /opt/mailcow-dockerized
sudo MAILCOW_BACKUP_LOCATION=/backup/mailcow ./helper-scripts/backup_and_restore.sh backup all --delete-days 7
Add to cron (every night), and copy the directory /backup/mailcow to another server or object storage — Borg or restic with encryption. 3-2-1 rule: three copies, two types of media, one off-site.
Restore — with the same script with parameter restore. Check recovery once a quarter on the test VM: a backup that has never been restored is a hope, not a backup.
If the server is a VM on KVM or Proxmox, additionally take snapshots/backups of the entire VM (Linux server and KVM series).
Step 8. Updates and monitoring#
cd /opt/mailcow-dockerized
sudo ./update.sh # сначала читайте заметки к релизу на GitHub
- update Mailcow monthly (releases often include security fixes), Ubuntu by
unattended-upgrades; - before the update — a fresh backup;
- monitor: disk space, Postfix queue length, certificate expiration, IP blacklisting, port availability 25/443/993. Ready-made tools — " Monitoring: Zabbix, Prometheus, and Grafana" series.
When your own server is a bad idea#
- there is no person who will update it every month and respond at night;
- the provider does not provide PTR or open port 25;
- you need to send mass mailings — use specialized services for them, otherwise the reputation of the main IP will be damaged and the work correspondence will suffer.
Checklist of your server#
- White static IP, not blacklisted, PTR =
mail.company.kz - Outgoing port 25 is open
- Docker from the official repository, no conflicts with ufw
- Password
adminchanged, 2FA for administrators - DKIM 2048, SPF, DMARC, MTA-STS, mail-tester score 9–10
- Daily backup to another site and recovery verification
- Monthly updates and monitoring of queue, drive, and blacklists
Next — email protection against phishing and hacking: Corporate mail, part 5: security — phishing, MFA, DMARC reports, archiving, and backup.
Comments · 0
No comments yet.Sign in to comment, rate and see all comments.