How to Self-Host Mailcow on a VPS (Complete Guide)
Mailcow is a powerful open-source email server suite based on Docker, which offers services like email hosting, calendar, and collaboration tools. Self-hosting Mailcow can give you full control over your email environment, and using a Virtual Private Server (VPS) is a practical solution for running Mailcow efficiently. In this guide, weโll take you through the steps to install and configure Mailcow on a VPS.
Prerequisites
Before you start, ensure you have the following ready:
- A VPS with at least 2 GB of RAM (4 GB recommended)
- An operating system: Ubuntu 20.04 or later
- A domain name pointed to your VPS
- Basic knowledge of Linux command line
Recommended VPS providers include:
| Provider | Starting Price | Features |
|---|---|---|
| Contabo VPS | 5.99 EUR/mo | SSD, DDoS protection |
| Hetzner Cloud | 4.15 EUR/mo | Flexible pricing, pay-as-you-go |
| DigitalOcean | 6 USD/mo | User-friendly interface |
| Vultr | 6 USD/mo | Global data centers |
| Linode (Akamai) | 5 USD/mo | Fast performance |
Choose a VPS provider that meets your budget and performance requirements. You can check out our full VPS comparison for more options.
Step 1: Set Up Your VPS
-
Create your VPS instance using your chosen provider and log in to your server via SSH:
ssh root@your_server_ip -
Update your system to ensure all existing packages are up-to-date:
apt update && apt upgrade -y -
Install required dependencies:
apt install curl git docker-compose -y
Step 2: Domain Configuration
-
Point your domainโs DNS records to your VPS IP address. Set up an A record for the base domain and subdomains that you will use for Mailcow (e.g., mail.yourdomain.com).
-
Allow some time for DNS propagation.
Step 3: Install Mailcow
-
Download the Mailcow installation files:
curl -L https://github.com/mailcow/mailcow-dockerized/archive/refs/heads/master.zip -o mailcow.zip unzip mailcow.zip cd mailcow-dockerized-master -
Copy the configuration file:
cp mailcow.conf.example mailcow.conf -
Edit the configuration by specifying your domain:
nano mailcow.conf- Set
MAILCOW_HOSTNAMEto your domain name, e.g.,mail.yourdomain.com.
- Set
-
Start Mailcow with Docker Compose:
docker-compose pull docker-compose up -d
Step 4: Configuration via the Web Interface
-
Access the Mailcow web interface by navigating to
https://mail.yourdomain.com. -
The default login credentials are:
- Username:
admin - Password:
moo@cow
- Username:
-
Configure your email aliases, domains, and other settings according to your requirements.
Step 5: Set Up DKIM and SPF Records
To enhance email deliverability, set up DKIM and SPF records:
- Create DKIM records by following the Mailcow interfaceโs instructions.
- Add SPF records to your DNS settings to specify which mail servers are permitted to send email on behalf of your domain.
Example SPF record:
v=spf1 a mx ip4:YOUR_VPS_IP -all
Step 6: Testing Your Setup
- Send a test email to verify deliverability.
- Check your spam folder to ensure the message didnโt get flagged.
FAQ
How do I update Mailcow once itโs installed?
Updating Mailcow is straightforward. First, navigate to the Mailcow installation directory, then use the following commands:
docker-compose pull
docker-compose up -d
This will download the latest Docker images and restart the services with the updated configurations. It is also wise to check the Mailcow documentation for specific version update notes.
What if I encounter SSL certificate issues?
If you are facing SSL certificate problems, consider using Letโs Encrypt for free SSL certificates. Mailcow has built-in support for Letโs Encrypt. Ensure that your DNS is properly configured before using the Letโs Encrypt feature in the Mailcow web interface. For more advanced configurations or troubleshooting, refer to various discussions in the r/selfhosted subreddit or on the Mailcow forums.
Can I run Mailcow on a low-spec VPS?
While Mailcow can technically run on a low-spec VPS, it is not recommended. Mailcowโs performance can be affected by limited RAM and CPU resources, especially if you are planning to handle multiple email accounts or if you run additional services alongside it. For a smoother experience, a VPS with at least 2-4 GB of RAM is ideal.
Conclusion
Self-hosting Mailcow on a VPS provides you with full control over your email systems. By following this step-by-step guide, you can successfully install and configure Mailcow to fit your personal or business needs. Remember to monitor your systemโs performance and adjust your server specs if necessary. Happy self-hosting!