Host Your Own Email Service

Host Your Own Email Service

Email is one of the last truly federated services on the internet—and yet most of us hand our most sensitive communications to Gmail, Outlook, or ProtonMail. I decided last year to take control by running my own mail server, and honestly, it's simpler than I expected. In this guide, I'll walk you through setting up a complete, production-ready email service that handles incoming and outgoing mail, spam filtering, and webmail access.

Why Self-Host Email?

Before we dive into the technical setup, let me be clear about the trade-offs. Self-hosted email means you own your data, control your backups, and aren't subject to corporate policy changes. But it also means you're responsible for security updates, DNS configuration, and deliverability monitoring. When I deployed my first mail server, I spent a week troubleshooting DKIM alignment and SPF records before mail actually arrived in people's inboxes.

The payoff? Complete independence. No one can lock you out, scan your mail for ads, or change their terms of service overnight. I use it daily for everything from personal correspondence to business email, and I haven't looked back.

Choose Your Platform: Mail-in-a-Box vs. Mailu

There are two excellent open-source email platforms for self-hosters: Mail-in-a-Box and Mailu.

Mail-in-a-Box is all-in-one: it handles DNS, SSL certificates, spam filtering, and backups automatically. You point your domain at it, run the installer, and you're live. I prefer Mail-in-a-Box for simplicity, especially if you're new to email servers.

Mailu is Docker-native and more modular. It's perfect if you already run a container infrastructure and want fine-grained control over individual components. Both are solid, but I'll focus on Mail-in-a-Box here because the setup is more straightforward.

Infrastructure Requirements

You'll need a VPS with a static IP address and root access. I strongly recommend a provider that doesn't block port 25 (SMTP). RackNerd's KVM VPS plans are reliable and affordable, starting around $10/month—plenty of capacity for a personal mail server handling a few mailboxes.

Minimum specs I'd recommend:

Watch out: Some cloud providers (AWS, Azure, DigitalOcean) block port 25 by default. Check their abuse policy. RackNerd doesn't—you can use it immediately.

Setting Up Mail-in-a-Box

I'll walk you through a fresh Ubuntu 22.04 LTS installation. You need a domain name pointing to your VPS's IP address and a clean server with nothing else running on ports 25, 53, 80, or 443.

# SSH into your VPS and update the system
ssh [email protected]
apt update && apt upgrade -y

# Mail-in-a-Box requires a fully qualified domain name
# Add this to /etc/hosts or verify your DNS is live
hostname mail.yourdomain.com
hostnamectl set-hostname mail.yourdomain.com

# Download and run the Mail-in-a-Box installer
cd /root
curl -O https://mailinabox.email/setup.sh
bash setup.sh

The installer is interactive. You'll be prompted for:

The script takes 15–30 minutes. It automatically:

Once complete, you'll see an admin panel URL. Log in and verify everything.

DNS Configuration

Mail-in-a-Box generates the DNS records you need. Access the admin panel at https://mail.yourdomain.com/admin and navigate to the DNS section. You'll see records for:

Copy these exact records into your domain registrar's DNS settings. This step is crucial—misconfigured DNS means your mail won't deliver or will be flagged as spam.

# After adding DNS records, verify them with dig
dig yourdomain.com MX
dig mail.yourdomain.com A
dig default._domainkey.yourdomain.com TXT
Tip: DNS propagation takes 24 hours. Mail-in-a-Box will warn you in the admin panel if records are missing. Don't add mailboxes until all DNS checks pass.

Creating Mailboxes and Using the Service

Once DNS is live, create mailboxes in the admin panel. I set up separate addresses for myself, family members, and a catch-all account.

For desktop mail clients, I use Thunderbird configured like this:

For webmail, Roundcube is built-in. Access it at https://mail.yourdomain.com with your email credentials. It's lightweight and mobile-friendly.

Spam Filtering and Greylisting

Mail-in-a-Box includes rspamd for spam detection and greylisting to reduce junk. Greylisting temporarily rejects incoming mail from unknown senders, then whitelists them after they retry. It's effective and transparent to legitimate mail.

Check spam filtering in the admin panel under "Mail > Spam Filter." I recommend enabling aggressive checks early on—you can always whitelist senders.

Backup Strategy

Mail-in-a-Box backs up to S3-compatible storage daily. I use Wasabi (cheap, S3-compatible), but you can also use AWS S3 or minio.

In the admin panel, go to "System > Backup" and enter your S3 credentials:

# Example: Wasabi S3 configuration
# Bucket: compacthost-mail-backup
# Region: us-west-1
# Access key: [from Wasabi console]
# Secret key: [from Wasabi console]

# Test the backup manually
sudo management/backup.py

I enable daily snapshots and keep a 30-day retention policy. If my server dies tomorrow, my mail is safe and recoverable.

Common Issues and Troubleshooting

When I first deployed this, I hit a few snags:

Mail bouncing or going to spam: Run the admin panel's "Diagnostics" tool. It checks DNS, certificates, and reverse DNS. Reverse DNS especially matters—ask your VPS provider to set it to mail.yourdomain.com.

Can't send mail on port 587: Verify your ISP or network doesn't block outbound SMTP. Use port 587 (submission) instead of 25, which is less likely to be blocked.

Certificate expired: Mail-in-a-Box auto-renews Let's Encrypt certificates, but check the admin panel occasionally. If renewal fails, SSH in and run:

sudo management/ssl_certificates.py

Next Steps: Going Bigger

Once you're comfortable with a single server, you can scale. Some homelabbers run Mail-in-a-Box on cheap VPS for personal use, while others scale to Mailu on Kubernetes for higher availability.

For redundancy, set up a secondary MX record pointing to another VPS. Mail won't be lost if your primary server is down for maintenance.

I also recommend setting up monitoring. Use Uptime Kuma to alert you if IMAP or SMTP goes down, and monitor disk space—a full mail server stops accepting mail.

Conclusion

Self-hosting email is genuinely one of the most empowering infrastructure projects you can undertake. It's not difficult, and it forces you to understand how email actually works. I've been running mine for over a year with zero downtime and complete reliability.

Start with Mail-in-a-Box, get it stable, and own your email. You'll never be locked out of your inbox again. If you need reliable hosting, check out RackNerd's VPS offerings—they're perfect for mail servers and won't block your ports.

Discussion

```