Email advanced ⏱ 90 minutes

Mailcow: Complete Email Server Suite

Full-featured email server with webmail, CalDAV, CardDAV, and spam filtering. Docker-based deployment.

By Homelab Team • 2025-01-15
#mailcow#email#smtp#webmail#docker

Introduction

Mailcow is a comprehensive, Docker-based mail server solution that bundles everything you need for a production-ready email infrastructure. It combines Postfix, Dovecot, SOGo groupware, Rspamd spam filtering, and ClamAV antivirus into a cohesive, web-managed platform that rivals enterprise email solutions.

Why Choose Mailcow?

All-in-One Solution: Mailcow includes SMTP, IMAP, webmail, calendars, contacts, spam filtering, virus scanning, and administration tools in a single integrated platform.

Modern Architecture: Built with Docker Compose, Mailcow isolates each service in containers for security, easy updates, and reliable operation. Updates are handled through a built-in update mechanism.

Production-Ready: Used by thousands of organizations worldwide, Mailcow handles everything from small homelabs to businesses with hundreds of mailboxes.

Active Development: Regular updates, security patches, and new features from a dedicated development team and active community.

Powerful Web Interface: Comprehensive administration panel for managing domains, mailboxes, aliases, spam settings, and monitoring without touching configuration files.

What You’ll Get

  • Email Services: Full SMTP/IMAP/POP3 server with TLS encryption
  • Webmail: Modern SOGo webmail interface with responsive design
  • Groupware: Integrated calendars and contacts with CardDAV/CalDAV
  • Security: Automatic spam filtering (Rspamd), virus scanning (ClamAV), and DKIM/SPF/DMARC
  • Monitoring: Built-in statistics, logs viewer, and quarantine management
  • Mobile Support: ActiveSync protocol for native mobile email apps
  • Backup Tools: Automated backup scripts for disaster recovery

Use Cases

Personal Email: Host your own [email protected] with complete privacy and control

Family Domain: Create mailboxes for family members with centralized administration

Small Business: Professional email infrastructure without recurring costs

Development/Testing: Test email functionality for applications in a controlled environment

Prerequisites

Hardware Requirements

Minimum Configuration:

  • CPU: 2 cores
  • RAM: 6GB (8GB recommended)
  • Storage: 20GB free space minimum (plan for mailbox growth)
  • Network: Static IP address, open ports 25, 80, 143, 443, 465, 587, 993, 995

Recommended Configuration:

  • CPU: 4+ cores (better spam filtering and virus scanning performance)
  • RAM: 16GB (handles multiple users and heavy scanning workloads)
  • Storage: 100GB+ SSD (fast storage improves database and search performance)
  • Network: Gigabit connection with low latency

Storage Planning:

  • Base installation: 5-10GB
  • Per-user mailbox: 2-10GB average (depends on usage)
  • Logs and temporary files: 5-10GB
  • Database and indexes: 2-5GB
  • Reserve 30-40% overhead for growth

Software Requirements

  • Operating System: Ubuntu 22.04 LTS, Debian 11/12, or RHEL 8/9 (Ubuntu recommended)
  • Docker: Version 20.10+
  • Docker Compose: Version 2.0+ (included with modern Docker)
  • Domain Name: Fully qualified domain name (FQDN) that you control
  • DNS Access: Ability to create DNS records (A, MX, TXT)
  • Clean IP: IP address not on spam blacklists

Important Prerequisites

Domain and DNS Control: You must own a domain name and have full DNS management access to create required records.

Clean IP Reputation: Check your server IP at MXToolbox Blacklist Check. If your IP is blacklisted, contact the listing service to delist before proceeding. VPS providers like Hetzner, Vultr, and DigitalOcean typically have clean IPs.

Reverse DNS (PTR): Your hosting provider must configure reverse DNS for your IP to point to your mail server hostname. This is critical for deliverability.

No Conflicting Services: Ensure no other mail server or web server is using ports 25, 80, 143, 443, 465, 587, 993.

Pre-Installation Checks

# Check Docker version
docker --version
# Should show 20.10 or newer

# Check Docker Compose version
docker compose version
# Should show 2.0 or newer

# Verify ports are available
sudo ss -tlnp | grep -E ':25|:80|:143|:443|:465|:587|:993|:995'
# Should return empty if ports are free

# Check available disk space
df -h /var/lib/docker
# Should show 20GB+ free

# Check available RAM
free -h
# Should show 6GB+ total RAM

# Verify hostname is set
hostname -f
# Should return your FQDN like mail.yourdomain.com

DNS Configuration

Proper DNS configuration is critical for email deliverability. Configure these records before installing Mailcow.

Required DNS Records

Replace yourdomain.com with your actual domain and YOUR-SERVER-IP with your server’s public IP address.

A Record (Mail Server):

mail.yourdomain.com.    3600    IN    A    YOUR-SERVER-IP

MX Record (Mail Exchanger):

yourdomain.com.    3600    IN    MX    10    mail.yourdomain.com.

TXT Record (SPF - Sender Policy Framework):

yourdomain.com.    3600    IN    TXT    "v=spf1 mx ~all"

TXT Record (DMARC - Domain-based Message Authentication):

_dmarc.yourdomain.com.    3600    IN    TXT    "v=DMARC1; p=quarantine; rua=mailto:[email protected]"

CNAME Records (Autodiscover - for Outlook/mobile apps):

autodiscover.yourdomain.com.    3600    IN    CNAME    mail.yourdomain.com.
autoconfig.yourdomain.com.      3600    IN    CNAME    mail.yourdomain.com.

DKIM Configuration (After Installation)

DKIM signing keys are generated during Mailcow installation. After setup, retrieve the DKIM public key from the Mailcow admin panel.

Steps to Add DKIM Record:

  1. Log into Mailcow web interface
  2. Navigate to Configuration > Configuration & Details
  3. Click on your domain
  4. Copy the DKIM public key (shows as dkim._domainkey)
  5. Create this DNS TXT record:
dkim._domainkey.yourdomain.com.    3600    IN    TXT    "v=DKIM1; k=rsa; p=YOUR-PUBLIC-KEY-HERE"

The public key will be a long string of characters. Copy it exactly as shown in the Mailcow interface.

PTR Record (Reverse DNS)

Contact your hosting provider to set up reverse DNS. The PTR record for your IP should resolve to your mail server hostname.

Request from provider:

PTR record for YOUR-SERVER-IP should resolve to mail.yourdomain.com

Verify PTR is configured:

dig -x YOUR-SERVER-IP +short
# Should return: mail.yourdomain.com.

DNS Verification

After configuring DNS, wait 5-15 minutes for propagation, then verify:

# Check A record
dig mail.yourdomain.com +short
# Should return: YOUR-SERVER-IP

# Check MX record
dig yourdomain.com MX +short
# Should return: 10 mail.yourdomain.com.

# Check SPF record
dig yourdomain.com TXT +short | grep spf
# Should return: "v=spf1 mx ~all"

# Check DMARC record
dig _dmarc.yourdomain.com TXT +short
# Should return: "v=DMARC1; p=quarantine; rua=mailto:[email protected]"

# Check reverse DNS
dig -x YOUR-SERVER-IP +short
# Should return: mail.yourdomain.com.

All records must resolve correctly before proceeding with installation.

Installation

Step 1: Prepare the System

Update system packages and configure hostname:

# Update system packages
sudo apt update && sudo apt upgrade -y

# Install required dependencies
sudo apt install -y curl git

# Set hostname (replace with your FQDN)
sudo hostnamectl set-hostname mail.yourdomain.com

# Update /etc/hosts
echo "YOUR-SERVER-IP mail.yourdomain.com mail" | sudo tee -a /etc/hosts

# Verify hostname
hostname -f
# Should output: mail.yourdomain.com

Step 2: Install Docker and Docker Compose

If Docker is not already installed:

# Install Docker using official script
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Add current user to docker group
sudo usermod -aG docker $USER

# Apply group changes (or logout and login)
newgrp docker

# Verify Docker installation
docker --version
docker compose version

Step 3: Download Mailcow

# Change to installation directory
cd /opt

# Clone Mailcow repository
sudo git clone https://github.com/mailcow/mailcow-dockerized
cd mailcow-dockerized

# Set proper ownership
sudo chown -R $USER:$USER /opt/mailcow-dockerized

Step 4: Generate Configuration

Run the Mailcow configuration generator:

# Generate mailcow.conf
./generate_config.sh

You’ll be prompted for:

Hostname (FQDN): Enter your mail server hostname: mail.yourdomain.com

Timezone: Enter your timezone (e.g., America/New_York, Europe/London, Asia/Tokyo)

The script will generate mailcow.conf with secure random passwords for database and services.

Step 5: Configure Mailcow Settings

Edit mailcow.conf to customize settings:

nano mailcow.conf

Key settings to review:

# Hostname (already set by generate_config.sh)
MAILCOW_HOSTNAME=mail.yourdomain.com

# Timezone
TZ=America/New_York

# HTTP and HTTPS ports (change if needed)
HTTP_PORT=80
HTTPS_PORT=443
HTTP_BIND=0.0.0.0
HTTPS_BIND=0.0.0.0

# Submit port (25 or 587, keep default)
SUBMISSION_PORT=587

# Database password (auto-generated, no need to change)
DBNAME=mailcow
DBUSER=mailcow
DBPASS=randomly-generated-password

# Skip Let's Encrypt (set to 'y' if using external reverse proxy)
SKIP_LETS_ENCRYPT=n

# Additional domains for SSL (optional)
ADDITIONAL_SAN=webmail.yourdomain.com,autodiscover.yourdomain.com

# Enable ClamAV antivirus (recommended, uses 1-2GB RAM)
SKIP_CLAMD=n

# Enable Solr full-text search (optional, uses 1-2GB RAM)
SKIP_SOLR=n

# Disable IPv6 if not available
DISABLE_IPV6=n

Memory Optimization: If you have limited RAM (6-8GB), consider setting SKIP_CLAMD=y to disable ClamAV. This saves 1-2GB RAM but removes virus scanning.

Save and exit (Ctrl+X, Y, Enter).

Step 6: Start Mailcow

Pull Docker images and start services:

# Pull all required images (may take 5-15 minutes)
docker compose pull

# Start Mailcow services
docker compose up -d

# Monitor initial startup (wait 2-5 minutes for all services to start)
docker compose logs -f
# Press Ctrl+C to exit log view

# Check all containers are running
docker compose ps

You should see approximately 20+ containers running, including:

  • nginx-mailcow
  • postfix-mailcow
  • dovecot-mailcow
  • rspamd-mailcow
  • redis-mailcow
  • mysql-mailcow
  • sogo-mailcow
  • php-fpm-mailcow
  • clamd-mailcow (if enabled)
  • solr-mailcow (if enabled)

Step 7: Access Web Interface

Open your browser and navigate to:

https://mail.yourdomain.com

Default Admin Credentials:

  • Username: admin
  • Password: moohoo

IMPORTANT: Change the admin password immediately after first login.

Change Admin Password:

  1. Click admin in top-right corner
  2. Select “Edit”
  3. Enter new secure password
  4. Save changes

Step 8: Verify SSL Certificate

Mailcow automatically obtains Let’s Encrypt SSL certificates. Verify certificate installation:

# Check certificate status
docker compose logs acme-mailcow | grep -i "success"

# Verify certificate files exist
ls -la data/assets/ssl/
# Should show cert.pem and key.pem

Browser should show valid SSL certificate when accessing https://mail.yourdomain.com with no warnings.

Configuration

Create Your First Domain

  1. Log into Mailcow admin interface
  2. Navigate to Configuration > Mail Setup
  3. Click Add domain

Domain Settings:

  • Domain: yourdomain.com
  • Max mailboxes: 10 (adjust as needed)
  • Max aliases: 50 (adjust as needed)
  • Max quota: 10240 MB (10GB per domain, adjust as needed)
  • Quota notification: 85% (optional email warning)
  • Backup MX: Leave unchecked (unless you have secondary mail server)
  • Relay all recipients: Leave unchecked
  • Active: Checked

Click Add to create domain.

Create Mailboxes

  1. Navigate to Mailboxes tab
  2. Click Add mailbox

Mailbox Configuration:

  • Username: Local part only (e.g., john for [email protected])
  • Domain: Select yourdomain.com from dropdown
  • Full name: John Doe
  • Quota: 2048 MB (2GB, adjust per user)
  • Password: Generate strong password (click dice icon)
  • Active: Checked

Advanced Options:

  • Force password change: Checked (user must change on first login)
  • Allow IMAP: Checked
  • Allow POP3: Checked (disable if not needed)
  • Allow SMTP: Checked
  • Spam filter: Checked
  • Quarantine notification: Daily (optional)

Click Add to create mailbox.

Create Additional Mailboxes: Repeat for each user you want to add.

Create Email Aliases

Aliases allow multiple email addresses to deliver to the same mailbox.

  1. Navigate to Configuration > Mail Setup > Aliases
  2. Click Add alias

Example Aliases:

Alias Configuration:

You can create aliases that forward to multiple recipients by entering multiple addresses (comma-separated).

Configure Spam Filter

Mailcow uses Rspamd for advanced spam filtering.

Adjust Spam Thresholds:

  1. Navigate to Configuration > Rspamd Settings
  2. Adjust score thresholds:
    • Reject score: 15 (emails with this score are rejected)
    • Add header score: 6 (emails marked as spam, delivered to inbox with header)
    • Greylist score: 4 (temporarily reject for verification)

Whitelist/Blacklist:

  1. Navigate to Configuration > Rspamd Settings > Whitelist/Blacklist
  2. Add trusted senders to whitelist
  3. Add known spammers to blacklist

Examples:

# Whitelist (trusted senders)
*@trusted-domain.com
[email protected]

# Blacklist (spam sources)
*@spam-domain.com
[email protected]

Configure DKIM Signing

DKIM signing is configured automatically for each domain.

Verify DKIM Configuration:

  1. Navigate to Configuration > Configuration & Details
  2. Select your domain from list
  3. View DKIM public key in “DKIM public key” section
  4. Verify DKIM TXT record exists in DNS (see DNS Configuration section)

Test DKIM Signing:

  1. Send test email to external account (Gmail, Outlook, etc.)
  2. View email headers
  3. Look for DKIM-Signature header
  4. Use DKIMValidator to verify signature

Configure Two-Factor Authentication (2FA)

Enable 2FA for admin account security:

  1. Click admin username (top-right corner)
  2. Select Edit
  3. Navigate to Two-Factor Authentication section
  4. Click Add TOTP
  5. Scan QR code with authenticator app (Authy, Google Authenticator, etc.)
  6. Enter 6-digit code to verify
  7. Save backup codes in secure location

Enable 2FA for Users:

Users can enable 2FA in their own account settings by logging into webmail (SOGo) or using the Mailcow user panel at https://mail.yourdomain.com/user.

Configure Quarantine

Mailcow quarantines suspected spam for review.

Quarantine Settings:

  1. Navigate to Configuration > Server Configuration > Quarantine
  2. Configure retention:
    • Retention days: 7 (how long to keep quarantined mail)
    • Max size: 50 MB (maximum size per quarantined message)

Release Quarantined Mail:

  1. Navigate to Quarantine in main menu
  2. Review quarantined messages
  3. Select messages to release or delete
  4. Click Release to deliver to inbox or Delete to remove permanently

Quarantine Notifications: Mailcow can send daily notification emails to users listing quarantined messages. Configure in per-mailbox settings.

Docker Compose Configuration

Here’s the complete docker-compose.yml that Mailcow generates. Understanding the services helps with troubleshooting and customization.

Key Services:

# Mailcow uses docker-compose.yml generated by the repository
# Location: /opt/mailcow-dockerized/docker-compose.yml

# Core Services:
# - nginx-mailcow: Web interface and reverse proxy
# - postfix-mailcow: SMTP server for sending/receiving mail
# - dovecot-mailcow: IMAP/POP3 server for retrieving mail
# - rspamd-mailcow: Spam filtering and DKIM signing
# - redis-mailcow: Cache and session storage
# - mysql-mailcow: Database for configuration and users
# - sogo-mailcow: Webmail, calendars, and contacts
# - php-fpm-mailcow: PHP processing for web interface
# - clamd-mailcow: Antivirus scanning
# - solr-mailcow: Full-text search indexing
# - acme-mailcow: Let's Encrypt certificate management
# - watchdog-mailcow: Service health monitoring

Resource Limits can be adjusted in docker-compose.override.yml:

# Create override file
nano docker-compose.override.yml

Add resource limits:

version: '2.1'

services:
  postfix-mailcow:
    deploy:
      resources:
        limits:
          memory: 1G
        reservations:
          memory: 512M

  dovecot-mailcow:
    deploy:
      resources:
        limits:
          memory: 2G
        reservations:
          memory: 1G

  rspamd-mailcow:
    deploy:
      resources:
        limits:
          memory: 2G
        reservations:
          memory: 1G

  clamd-mailcow:
    deploy:
      resources:
        limits:
          memory: 2G
        reservations:
          memory: 1G

Apply changes:

docker compose down
docker compose up -d

Email Client Configuration

Configure email clients to connect to your Mailcow server.

Automatic Configuration

Mailcow provides autodiscover/autoconfig for automatic configuration in Outlook, Thunderbird, and mobile devices.

Ensure DNS records are set:

  • autodiscover.yourdomain.com CNAME to mail.yourdomain.com
  • autoconfig.yourdomain.com CNAME to mail.yourdomain.com

Clients will automatically detect settings when you enter [email protected] and password.

Manual Configuration

IMAP Settings (Recommended for receiving mail):

  • Server: mail.yourdomain.com
  • Port: 993
  • Security: SSL/TLS
  • Authentication: Normal password
  • Username: Full email address ([email protected])

SMTP Settings (For sending mail):

  • Server: mail.yourdomain.com
  • Port: 587
  • Security: STARTTLS
  • Authentication: Normal password
  • Username: Full email address ([email protected])

POP3 Settings (Alternative to IMAP):

  • Server: mail.yourdomain.com
  • Port: 995
  • Security: SSL/TLS
  • Authentication: Normal password
  • Username: Full email address ([email protected])

Mobile Devices

iOS (iPhone/iPad):

  1. Settings > Mail > Accounts > Add Account
  2. Select “Other”
  3. Enter email and password
  4. iOS should auto-configure using autodiscover

Android:

  1. Open email app (Gmail app supports external accounts)
  2. Add account > Other
  3. Enter email and password
  4. Android should auto-configure using autoconfig

ActiveSync is also available for native calendar and contacts sync:

  • Server: mail.yourdomain.com
  • Domain: Leave blank
  • Username: Full email address
  • Use SSL: Yes

Webmail Access

Users can access email through SOGo webmail:

https://mail.yourdomain.com/SOGo

SOGo Features:

  • Modern responsive webmail interface
  • Integrated calendar with event scheduling
  • Shared calendars for team collaboration
  • Contact management with CardDAV
  • Email filtering rules
  • Out-of-office auto-responder
  • Email signatures
  • Multiple identities

Security Hardening

Firewall Configuration

Configure firewall to allow only necessary ports:

# Using UFW (Ubuntu/Debian)
sudo apt install ufw

# Allow SSH (if using SSH for management)
sudo ufw allow 22/tcp

# Allow HTTP (for Let's Encrypt challenges)
sudo ufw allow 80/tcp

# Allow HTTPS (web interface)
sudo ufw allow 443/tcp

# Allow SMTP (incoming mail)
sudo ufw allow 25/tcp

# Allow IMAP SSL (email retrieval)
sudo ufw allow 993/tcp

# Allow POP3 SSL (email retrieval)
sudo ufw allow 995/tcp

# Allow Submission (authenticated sending)
sudo ufw allow 587/tcp

# Allow SMTPS (alternative authenticated sending)
sudo ufw allow 465/tcp

# Enable firewall
sudo ufw enable

# Check firewall status
sudo ufw status verbose

Fail2Ban Integration

Mailcow includes built-in Fail2Ban to block brute-force attacks.

View Fail2Ban Status:

# Check banned IPs
docker compose exec dovecot-mailcow fail2ban-client status dovecot
docker compose exec postfix-mailcow fail2ban-client status postfix-sasl
docker compose exec sogo-mailcow fail2ban-client status sogo-auth

Unban IP Address:

# Unban from dovecot jail
docker compose exec dovecot-mailcow fail2ban-client set dovecot unbanip IP-ADDRESS

# Unban from postfix jail
docker compose exec postfix-mailcow fail2ban-client set postfix-sasl unbanip IP-ADDRESS

Whitelist Trusted IPs:

  1. Navigate to Configuration > Server Configuration > Fail2Ban
  2. Add trusted IPs to whitelist (your home IP, office IP, etc.)
  3. Format: One IP per line or CIDR notation (192.168.1.0/24)

Enable SPF, DKIM, and DMARC

These are configured automatically by Mailcow, but verify they’re working:

Test Email Authentication:

  1. Send test email to mail-tester.com
  2. Check score (should be 9/10 or 10/10)
  3. Review SPF, DKIM, and DMARC results

Common Issues:

  • SPF Fails: Check DNS TXT record for yourdomain.com
  • DKIM Fails: Verify DKIM public key TXT record at dkim._domainkey.yourdomain.com
  • DMARC Fails: Check TXT record at _dmarc.yourdomain.com

Regular Security Updates

Keep Mailcow updated to receive security patches:

# Change to Mailcow directory
cd /opt/mailcow-dockerized

# Check for updates
./update.sh --check

# Perform update (includes automatic backup)
./update.sh

# Follow prompts, update typically takes 5-10 minutes

Automatic Update Checking: Enable automatic update notifications in Configuration > System.

Backup Configuration

Mailcow Backup Script:

# Create backup
cd /opt/mailcow-dockerized
./helper-scripts/backup_and_restore.sh backup all

# Backups are stored in /opt/mailcow-dockerized/data/assets/backup
ls -lah data/assets/backup/

Scheduled Automated Backups:

# Create backup script
sudo nano /usr/local/bin/mailcow-backup.sh

Add content:

#!/bin/bash
cd /opt/mailcow-dockerized
./helper-scripts/backup_and_restore.sh backup all

# Optional: Copy backup to remote location
# rsync -avz data/assets/backup/ user@backup-server:/backups/mailcow/

Make executable and schedule:

sudo chmod +x /usr/local/bin/mailcow-backup.sh

# Add to crontab (daily at 2 AM)
sudo crontab -e

Add line:

0 2 * * * /usr/local/bin/mailcow-backup.sh >> /var/log/mailcow-backup.log 2>&1

Restore from Backup:

cd /opt/mailcow-dockerized
./helper-scripts/backup_and_restore.sh restore
# Follow prompts to select backup file

SSL/TLS Configuration

Mailcow uses strong TLS by default. Verify configuration:

Check TLS Settings:

  1. Navigate to Configuration > Server Configuration > TLS
  2. Review enabled protocols:
    • TLS 1.2: Enabled
    • TLS 1.3: Enabled
    • TLS 1.1: Disabled (insecure)
    • TLS 1.0: Disabled (insecure)

Test TLS Configuration:

# Test SMTP TLS
openssl s_client -connect mail.yourdomain.com:587 -starttls smtp

# Test IMAP TLS
openssl s_client -connect mail.yourdomain.com:993

# Or use online tool
# Visit: https://ssl-tools.net and test your mail server

Troubleshooting

Cannot Send or Receive Email

Check Service Status:

docker compose ps

# All services should show "Up" status
# If any service is down, check logs:
docker compose logs postfix-mailcow
docker compose logs dovecot-mailcow

Check DNS Configuration:

# Verify MX record
dig yourdomain.com MX +short

# Verify A record
dig mail.yourdomain.com +short

# Check reverse DNS
dig -x YOUR-SERVER-IP +short

Check Firewall:

# Verify ports are open
sudo ss -tlnp | grep -E ':25|:587|:993'

# Check if firewall is blocking
sudo ufw status verbose

Check Mail Queue:

# View queued messages
docker compose exec postfix-mailcow postqueue -p

# View mail log
docker compose exec postfix-mailcow tail -f /var/log/syslog

Emails Going to Spam

Test Email Reputation:

Send test email to mail-tester.com and check score.

Common Issues:

  1. Missing DKIM Signature: Verify DKIM DNS record is published
  2. SPF Fails: Check SPF TXT record includes mx
  3. Reverse DNS Missing: Contact hosting provider to configure PTR record
  4. IP Blacklisted: Check at MXToolbox and request delisting

View Email Headers:

Check headers of delivered email to see authentication results:

  • Authentication-Results header shows SPF, DKIM, DMARC results
  • All three should show pass

High Memory Usage

Check Resource Usage:

docker stats

# Look for containers using excessive memory
# Common culprits: rspamd-mailcow, clamd-mailcow, solr-mailcow

Reduce Memory Usage:

# Edit mailcow.conf
nano mailcow.conf

# Disable ClamAV if not needed (saves 1-2GB)
SKIP_CLAMD=y

# Disable Solr if not using full-text search (saves 1-2GB)
SKIP_SOLR=y

# Restart Mailcow
docker compose down
docker compose up -d

Limit Container Resources: Use docker-compose.override.yml to set memory limits (see Docker Compose Configuration section).

Database Errors

Database Connection Issues:

# Check MySQL container
docker compose logs mysql-mailcow

# Restart MySQL
docker compose restart mysql-mailcow

# If corrupted, restore from backup
cd /opt/mailcow-dockerized
./helper-scripts/backup_and_restore.sh restore

Optimize Database:

# Run optimization
docker compose exec mysql-mailcow mysql_upgrade -u root -p
# Enter MySQL root password from mailcow.conf

# Restart MySQL
docker compose restart mysql-mailcow

Web Interface Not Accessible

Check Nginx Container:

# View nginx logs
docker compose logs nginx-mailcow

# Restart nginx
docker compose restart nginx-mailcow

Check SSL Certificate:

# View ACME (Let's Encrypt) logs
docker compose logs acme-mailcow

# Force certificate renewal
docker compose exec acme-mailcow acme.sh --renew -d mail.yourdomain.com --force

Check Port Binding:

# Verify nginx is bound to ports 80 and 443
docker compose ps nginx-mailcow

# Check if another service is using the ports
sudo ss -tlnp | grep -E ':80|:443'

Slow Performance

Check Disk I/O:

# Monitor disk usage
iostat -x 1

# Check if disk is full
df -h

Optimize Database:

# Analyze and optimize tables
docker compose exec mysql-mailcow mysqlcheck -u root -p mailcow --auto-repair --optimize

Clear Old Logs:

# Clean up old mail logs
docker compose exec postfix-mailcow find /var/log -name "*.log" -mtime +30 -delete

# Clean up old quarantine
# Navigate to Configuration > Quarantine in web interface and reduce retention days

Increase Container Resources: If server has adequate RAM/CPU, increase allocation to containers via docker-compose.override.yml.

Advanced Configuration

Configure Outbound Relay

If your ISP blocks port 25, use a relay server:

# Edit relay configuration
nano data/conf/postfix/relayhost_map

Add relay configuration:

@yourdomain.com    [smtp-relay.gmail.com]:587

Configure authentication:

nano data/conf/postfix/sasl_passwd

Add credentials:

[smtp-relay.gmail.com]:587    [email protected]:app-password

Apply changes:

docker compose exec postfix-mailcow postmap /opt/postfix/conf/relayhost_map
docker compose exec postfix-mailcow postmap /opt/postfix/conf/sasl_passwd
docker compose restart postfix-mailcow

Multiple Domains

Add additional domains to host email for multiple organizations:

  1. Navigate to Configuration > Mail Setup
  2. Click Add domain
  3. Enter new domain name
  4. Configure DNS records for new domain (MX, SPF, DKIM, DMARC)
  5. Create mailboxes under new domain

Each domain operates independently with separate mailboxes and settings.

Custom Branding

Customize the Mailcow web interface:

# Edit branding file
nano data/web/inc/vars.local.inc.php

Add custom variables:

<?php
$UI_TEXTS['main_name'] = 'Your Company Mail';
$UI_TEXTS['title_name'] = 'Your Company Mail Server';

Restart PHP container:

docker compose restart php-fpm-mailcow

API Integration

Mailcow provides a REST API for automation.

Generate API Key:

  1. Log into admin interface
  2. Navigate to Access > API
  3. Click Create API key
  4. Enter description: “Automation scripts”
  5. Allow read/write access as needed
  6. Copy generated API key

Example API Call:

# List all mailboxes
curl -X GET "https://mail.yourdomain.com/api/v1/get/mailbox/all"   -H "X-API-Key: YOUR-API-KEY-HERE"

# Create new mailbox
curl -X POST "https://mail.yourdomain.com/api/v1/add/mailbox"   -H "X-API-Key: YOUR-API-KEY-HERE"   -H "Content-Type: application/json"   -d '{
    "local_part": "newuser",
    "domain": "yourdomain.com",
    "name": "New User",
    "password": "SecurePassword123",
    "quota": 2048,
    "active": 1
  }'

API Documentation: Available at https://mail.yourdomain.com/api

Monitoring and Maintenance

View Logs

# View all logs
docker compose logs -f

# View specific service logs
docker compose logs -f postfix-mailcow
docker compose logs -f dovecot-mailcow
docker compose logs -f rspamd-mailcow

# View mail queue
docker compose exec postfix-mailcow mailq

Email Queue Management

# View queue
docker compose exec postfix-mailcow postqueue -p

# Flush queue (force immediate delivery)
docker compose exec postfix-mailcow postqueue -f

# Delete specific message from queue
docker compose exec postfix-mailcow postsuper -d MESSAGE-ID

# Delete all queued messages
docker compose exec postfix-mailcow postsuper -d ALL

Statistics and Monitoring

Built-in Statistics:

  1. Navigate to System > Stats in web interface
  2. View graphs for:
    • Received messages
    • Sent messages
    • Spam detected
    • Virus detected
    • Storage usage

External Monitoring: Consider integrating with Prometheus/Grafana for advanced monitoring.

Next Steps

  1. Set Up Automated Backups: Schedule daily backups to remote location
  2. Configure Monitoring: Set up Uptime Kuma or similar to monitor service availability
  3. Add Additional Domains: Host email for multiple domains/organizations
  4. Migrate Existing Email: Import email from previous provider
  5. Document User Guides: Create documentation for users on connecting devices

Conclusion

You now have a production-ready Mailcow email server with:

  • Complete SMTP/IMAP/POP3 email services
  • Webmail with calendars and contacts
  • Spam filtering and virus scanning
  • DKIM, SPF, and DMARC authentication
  • Secure TLS encryption
  • Web-based administration

Key Success Metrics:

  • Email deliverability to Gmail/Outlook without spam folder placement
  • All DNS records configured and verified
  • SSL/TLS certificates valid and auto-renewing
  • Spam filter catching 95%+ of spam
  • Regular automated backups working
  • Users able to send and receive email on all devices

Mailcow provides enterprise-grade email infrastructure for homelabs and small businesses. With proper DNS configuration and regular maintenance, your mail server will deliver reliable email service for years to come.

Community Resources:

Welcome to self-hosted email!