Is Self-hosting mail servers recommended? #2
-
|
Hi, What should I do, if I wanna self-host a server? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Is self-hosting a mail server recommended?If you want a practical, modern, “works out of the box” self-hosted setup, Mailcow (Dockerized) is a solid choice. Self-hosted mail server (Debian/Ubuntu) — step-by-step0) What you need (before you start)
1) Buy a VPSMinimum practical:
Record:
2) Buy a domainExample domain: You will use:
3) DNS: move nameservers to Cloudflare
4) Set PTR / rDNS (critical)In your VPS provider panel, set PTR (Reverse DNS) for your server IP:
Also ensure forward DNS matches:
5) Cloudflare DNS records to create (mail-related)In Cloudflare → DNS create: A / AAAA (mail host)
MX (mail exchanger)
SPF (basic)
DKIM (Mailcow will generate this; you add it later)
DMARC (start with monitoring, then tighten)
Autodiscover / Autoconfig (optional convenience)
6) Prepare the server (Debian/Ubuntu)Update systemsudo apt update && sudo apt -y upgrade
sudo rebootSet hostnamesudo hostnamectl set-hostname mail.email.xyzInstall dependenciessudo apt update
sudo apt -y install \
ca-certificates curl gnupg lsb-release ufw git7) Install Docker + Docker Compose (plugin)Docker repo + installsudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg \
| sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) stable" \
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginEnable Dockersudo systemctl enable --now docker(Optional) run docker without sudo: sudo usermod -aG docker "$USER"
newgrp docker8) Firewall (UFW)Open only what you need: sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
# SMTP
sudo ufw allow 25/tcp
sudo ufw allow 465/tcp
sudo ufw allow 587/tcp
# IMAP
sudo ufw allow 143/tcp
sudo ufw allow 993/tcp
# HTTP/HTTPS for webmail/admin + ACME
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status9) Install Mailcow (Dockerized)Clone Mailcowcd ~
git clone https://github.com/mailcow/mailcow-dockerized.git
cd mailcow-dockerizedGenerate config./generate_config.shWhen prompted:
Start Mailcowsudo docker compose pull
sudo docker compose up -dCheck status: sudo docker compose ps10) Initial Mailcow setupAccess web UIOpen in browser:
(If TLS is not ready yet, give it a minute and ensure ports 80/443 are reachable.) Login / adminMailcow provides initial credentials in setup docs/UI.
11) Add DKIM + verify DNSIn Mailcow UI:
Then in Cloudflare DNS add:
12) Verify everything (deliverability basics checklist)DNS should be consistent
SPF/DKIM/DMARC present
Practical notes (important)Provider restrictions
BackupsAt minimum back up:
UpdatesMail servers must be patched frequently.
If you want “simpler than Mailcow”Mailcow is “simple for a full stack”, but still heavy.
Summary (fast path)
|
Beta Was this translation helpful? Give feedback.
Is self-hosting a mail server recommended?
If you want a practical, modern, “works out of the box” self-hosted setup, Mailcow (Dockerized) is a solid choice.
Self-hosted mail server (Debian/Ubuntu) — step-by-step
0) What you need (before you start)
email.xyz).1) Buy a VPS
Minimum practical: