(Works on Hetzner, DigitalOcean, and any provider that allows mail ports)
This guide explains how to set up a production-ready mail server using Mailcow, an open-source mail suite that includes Postfix, Dovecot, Rspamd, ClamAV, and a modern web UI.
A self-hosted mail server gives you full control over your email infrastructure. It improves privacy and can be used for a variety of purposes such as internal communications, outreach campaigns, or customer support.
Mailcow works on any VPS or dedicated server that allows mail ports (25, 465, 587). Many providers, for example DigitalOcean, block port 25 by default. Verify your provider’s policies and request unblocking if needed.
Before starting, ensure you have:
example.com) with DNS management access for your server and sending domains.Log in to your server using SSH as the root user. Update the system, set a proper hostname if required, and reboot to apply changes.
# Connect to the server with SSH in your terminal
ssh root@YOUR_SERVER_IP
# Update the system
apt update && apt upgrade -y
# Reboot the server to apply changes
reboot
Add the following DNS records to your domain for proper email delivery:
mail.example.com → YOUR_SERVER_IP example.com → mail.example.com (priority 10) v=spf1 mx ip4:YOUR_SERVER_IP ~all v=DMARC1; p=quarantine; rua=mailto:[email protected]Install Docker and Docker Compose, which Mailcow uses to run its containers. Then verify the installation by checking their versions.
# Install Docker (official script)
curl -fsSL https://get.docker.com | sh
# Enable and start Docker
sudo systemctl enable docker
sudo systemctl start docker
# Install Docker Compose plugin
sudo apt update
sudo apt install -y docker-compose-plugin
# Verify installation
docker --version
docker compose version
Clone the Mailcow repository to your server and navigate to the Mailcow directory.
# Switch to /opt
cd /opt
# Clone repository
sudo git clone https://github.com/mailcow/mailcow-dockerized.git
# Switch to correct working directory
cd /opt/mailcow-dockerized
Regularly check the github repository for new issues / updates.
After changing your working directory, run the Mailcow configuration script to generate mailcow.conf.
Specify your mail server hostname, timezone, and network settings.
# Generate mailcow.conf
sudo ./generate_config.sh
Mailcow requires several ports for email and web access:
Configure your firewall to allow traffic on these ports.
# SMTP
sudo ufw allow 25
sudo ufw allow 465
sudo ufw allow 587
# POP3
sudo ufw allow 110
sudo ufw allow 995
# IMAP
sudo ufw allow 143
sudo ufw allow 993
# HTTP / HTTPS
sudo ufw allow 80
sudo ufw allow 443
# Enable firewall
sudo ufw enable
sudo ufw status
Pull Docker images and start Mailcow using Docker Compose.
Check that all containers are running correctly.
# Pull images
docker compose pull
# Start Mailcow
docker compose up -d
# Verify containers
docker compose ps
Open your browser and navigate to your Mailcow Web UI:https://mail.example.com
Default credentials are:
admin moohooChange these immediately in the UI. The mailcow UI also allows you to manage domains, users, mailboxes, and DKIM keys.
Configure reverse DNS (PTR) for your server IP to point to mail.example.com. This improves email deliverability and reduces the chance of your emails being flagged as spam.
Reverse DNS configuration is provider-specific. Follow your hosting provider’s documentation to complete this step. We will use Hetzner as example below.
To configure reverse DNS on Hetzner Cloud, follow these steps:
mail.example.com. ::1.In the Mailcow UI:
Send test emails to Gmail, Outlook, or ProtonMail and check headers for SPF, DKIM, and DMARC compliance. Use tools like Google Postmaster for validation.
To keep your Mailcow server secure and reliable, follow these essential best practices:
/var/lib/docker/volumes Always ensure SPF, DKIM, and DMARC* for your sending domains are properly configured before you start sending, or your emails will land in spam.
If you run into problems with your Mailcow server, the following are some common issues and how to resolve them:
For IP reputation checks, use:
A self-hosted Mailcow can be a cost-effective, versatile tool that powers a wide range of email-related workflows, such as:
Mailcow provides enterprise-grade email on your own infrastructure, giving you more control, privacy, and flexibility than most hosted solutions.
It can also be a good choice for high volume outbound email campaigns, but only with the right scaling approach. Avoid high-volume email campaigns from a single IP.
If you plan to use mailcow for outbound, make sure to include IP warm-up for marketing campaigns. Consider SMTP relay fallback, a deployment pipeline and automated backups. If done right, this will keep your deliverability high and your setup reliable over time.
Browse more of our most popular articles, packed with practical advice, in-depth analysis, and strategies to improve your marketing and sales performance.
Discover how Salesnode can help you drive more traffic to your offer, follow up with your leads, and book more appointments with qualified prospects ready to buy.
Get Early Access