How to Host Your Own Email Server with Open Source Tools
You can run a full email server on a cheap VPS using Mailu. It bundles Postfix, Dovecot, and webmail behind Docker so setup stays simple.
Start with these basics before you touch any code. Pick a VPS with at least 2 GB RAM and a static IP. Point your domain’s A record at that IP. Set reverse DNS to match the hostname you choose.
Install Mailu on Debian 12
Log in as root and install Docker first.
- Run
apt update && apt install docker.io docker-compose -y. - Create a folder:
mkdir /opt/mailu && cd /opt/mailu. - Download the setup script and answer its questions about your domain and admin email.
- Edit docker-compose.yml only if you need to change ports or add volumes for backups.
- Start everything with
docker-compose up -d.
Mailu takes a few minutes to finish. Once it does, open https://yourdomain.com and log in with the admin account it created.
| Item | Example value |
|---|---|
| Domain | example.com |
| Hostname | mail.example.com |
| Admin email | [email protected] |
Check these items right after the containers start:
- Firewall allows ports 25, 587, 993, and 80/443.
- SPF and DKIM records are added through the Mailu admin panel.
- Test sending and receiving with a second address you control.
Daily maintenance means watching the logs with docker-compose logs -f and keeping the images updated monthly. Back up the /opt/mailu directory so you can restore accounts quickly if the VPS fails.