Mailcow
Install a complete self-hosted mail server with Mailcow Dockerized, SMTP, IMAP, webmail, anti-spam and DKIM included
Mailcow Dockerized is a complete mail server stack running entirely on Docker. It includes Postfix (SMTP), Dovecot (IMAP), SOGo (webmail), Rspamd (anti-spam), ClamAV (antivirus), automatic TLS and a web admin panel.
Prerequisites
- Minimum 2 vCPU, 4 GB RAM (6 GB recommended with ClamAV)
- A dedicated domain or subdomain, e.g.
mail.yourdomain.com - Ports 25, 80, 110, 143, 443, 465, 587, 993, 995 open on the firewall
- Reverse DNS (PTR) set to
mail.yourdomain.com: essential for email deliverability - Docker and Docker Compose installed
Many VPS providers block port 25 by default to prevent spam. Check with DeluxHost support if your VPS has outbound port 25 open before proceeding.
DNS Configuration
Before installing, configure these DNS records for your domain:
| Type | Name | Value |
|---|---|---|
| A | mail | YOUR_SERVER_IP |
| MX | @ | mail.yourdomain.com (priority 10) |
| TXT | @ | v=spf1 mx ~all |
| CNAME | autodiscover | mail.yourdomain.com |
| CNAME | autoconfig | mail.yourdomain.com |
DKIM and DMARC records will be configured after installation.
Installation
Clone the repository
cd /opt
git clone https://github.com/mailcow/mailcow-dockerized
cd mailcow-dockerizedGenerate configuration
./generate_config.shThe script will ask:
- Mail server hostname (FQDN):
mail.yourdomain.com - Timezone: e.g.
Europe/Rome
This generates the mailcow.conf file.
Start Mailcow
docker compose pull
docker compose up -dThe first startup takes several minutes. Monitor with:
docker compose logs -fFirst Access
Open https://mail.yourdomain.com in your browser.
Default credentials:
- Username:
admin - Password:
moohoo
Change the admin password immediately from Configuration → Access → Admin password.
Creating a Mailbox
- Go to Mail Setup → Domains → Add domain
- Add
yourdomain.comand click Save - Go to Mailboxes → Add mailbox
- Fill in username, full name and password
- Click Add
DKIM Configuration
DKIM digitally signs outgoing emails, essential for deliverability.
- Go to Configuration → ARC/DKIM keys
- Select your domain
- Click Generate (or use key length 2048)
- Copy the DKIM TXT record shown
- Add it to your DNS as a TXT record on
dkim._domainkey.yourdomain.com
DMARC record (recommended)
Add a TXT record on _dmarc.yourdomain.com:
v=DMARC1; p=quarantine; rua=mailto:dmarc@yourdomain.com; ruf=mailto:dmarc@yourdomain.com; fo=1Start with p=none to monitor without rejecting emails, then switch to p=quarantine or p=reject once everything is working.
Email Client Configuration
IMAP (incoming mail)
- Server:
mail.yourdomain.com - Port: 993 (SSL/TLS)
SMTP (outgoing mail)
- Server:
mail.yourdomain.com - Port: 587 (STARTTLS) or 465 (SSL/TLS)
Webmail (SOGo)
- URL:
https://mail.yourdomain.com/SOGo
Maintenance and Updates
Update Mailcow
cd /opt/mailcow-dockerized
# Pull update script
./update.shThe script handles stopping containers, pulling new images and restarting.
Backup
# Backup all data
cd /opt/mailcow-dockerized
./helper-scripts/backup_and_restore.sh backup allBackups are saved to /var/mailcow_backups/ by default.
Restore
./helper-scripts/backup_and_restore.sh restoreUseful Commands
# Check all container status
cd /opt/mailcow-dockerized
docker compose ps
# View logs for a specific service
docker compose logs -f postfix-mailcow
docker compose logs -f rspamd-mailcow
docker compose logs -f dovecot-mailcow
# Restart a single service
docker compose restart postfix-mailcow
# Restart all Mailcow
docker compose restartRspamd (Anti-spam)
Rspamd is the anti-spam engine. Access its web interface at:
https://mail.yourdomain.com/rspamd
The password is in mailcow.conf:
grep RSPAMD_PASSWORD /opt/mailcow-dockerized/mailcow.confFrom the Rspamd interface you can view scores of analyzed emails, whitelist/blacklist senders and adjust spam thresholds.
Deliverability Check
After configuration, verify your mail server with:
- mail-tester.com, sends an email to check SPF, DKIM, DMARC
- mxtoolbox.com, verifies MX, blacklists, PTR
A score of 10/10 on mail-tester is achievable with Mailcow if SPF, DKIM, DMARC and reverse DNS are configured correctly. This is essential to avoid emails landing in spam with Gmail, Outlook and other providers.