Roll Your Own Email Server

De-monopolizing my digital life has been something I've been chipping away at for a while now, and the lowest hanging fruit turned out to be email. Letting Google — or any monopoly, really — sit inside one of the most intimate corners of my digital life started to feel less like convenience and more like a bad deal I'd sleepwalked into. I'd been lurking on /r/selfhosted long enough to absorb the conventional wisdom that self-hosted email is a nightmare: unreliable, blacklisted, a maintenance burden you'll regret. But I've learned to be skeptical of internet strangers' war stories, so I figured I'd find out for myself.

Choosing Mail-in-a-Box

I spent some time going back and forth between Mail-in-a-Box and Mailcow before settling on MiaB. The deciding factor was boring but real: lower RAM requirements, which translates directly to lower monthly hosting costs. When you're running personal infrastructure, every dollar saved on a VM is a dollar you're not paying as a tax on your own curiosity.

Picking a Host

After comparing a handful of providers, two stood out for offering reasonably priced tiers alongside available credits. Linode won out — for $5/month you get a Nanode with 1 GB RAM and 25 GB SSD storage, which is exactly what MiaB needs. More importantly, the sign-up credits Linode offers stretch far enough to cover roughly the first four months of hosting for free, which makes this experiment essentially zero cost to start. Vultr offers the same 1 GB RAM / 25 GB SSD configuration at the same $5/month price point, and their $50 sign-up credit sounds generous until you read the fine print: it expires after the first month, which makes it a better fit for a beefier deployed service than for a lean email box quietly humming along. I'll be putting Vultr to work on other projects down the road, but for this one, Linode was the clear call.

For domain registration, I use NameSilo as my go-to registrar. Cheap domain names with privacy baked in by default — no having to remember to opt into WHOIS protection every renewal cycle.

Spinning Up the Server

From the Linode account page, click into Linodes and create a new instance with the following configuration. For the distribution, choose Ubuntu 18.04 LTS. For the region, pick whatever's geographically closest to you — or closest to your VPN exit node if you're always on one. Linode offers a speedtest to help you decide, though keep in mind VPN traffic can skew those results. Select the Nanode 1GB plan. For the label, something like us-${optional-region}-mail keeps things tidy, and tag it mail-in-a-box so it doesn't get lost in your account later.

For the root password, this is not the place to be lazy — use a password manager and generate something strong. I've been using BitWarden, which is open source, has a self-hosted option, and has an active developer who shows up in /r/bitwarden. Highly recommend. For the SSH key, on macOS you can copy your public key to the clipboard with pbcopy < ~/.ssh/id_rsa.pub and paste it directly into the Linode UI. If you need a primer on generating SSH keys, GitHub has thorough documentation on exactly that. Optionally enable a Private IP, then click Create.

Once the instance is up, navigate to the Networking tab. For both IPv4 and IPv6, click the ellipsis next to each address, select Edit RDNS, and set your domain name (e.g., example.com) as the reverse DNS entry. This is one of those steps that's easy to skip and annoying to debug later when your mail gets flagged, so do it now.

Glue Records

The relationship between your domain name and your IP address is, as MiaB's own documentation diplomatically puts it, "complicated." DNS is a globally distributed system, and both your registrar and your box have a role to play in it. Glue records are how you tell the world that your nameservers are authoritative for your own domain — without them, you'd have a circular dependency where resolving your nameservers requires resolving your domain, which requires your nameservers.

Head over to NameSilo and open your domain console. Find the NameServers panel and click View/Manage Registered NameServers. You need to register two nameserver hostnames — ns1.yourdomain.com and ns2.yourdomain.com — both pointing at your Linode's public IP address. Click Register New NameServer, set the host to ns1 plus your registered domain, and enter your Linode public IP as Host IP 1. Repeat the same steps for ns2. Once both are registered, go back to your Domain Console and update the authoritative nameservers for the domain to point to those two new ns1/ns2 names.

Installing Mail-in-a-Box

We're in the home stretch. Back in your Linode account, grab the SSH connection string from the Networking tab and open your terminal. It's a two-step operation:

# ssh into the box
ssh [email protected]

# install the service
curl -s https://mailinabox.email/setup.sh | sudo -E bash

Follow the prompts for your admin MiaB username and domain. I chose to remove the box.* subdomain since this domain exists purely for email. Once the installer finishes, you can reach the control panel using the admin credentials you set during setup.

Fair warning: the setup script failed on me once or twice while trying to pull some JavaScript assets. Don't panic — running sudo mailinabox is idempotent enough that you can just run it again. It sorted itself out after a couple of attempts. Once you're through, the script output will hand you the URL for the admin portal. From there, the Mail-in-a-Box admin interface walks you through any remaining system checks and configuration steps. If you hit a wall, Linode's own guide for getting MiaB running on their nodes is a solid reference.

Happy emailing — from infrastructure you actually own.

Comments 0

Leave a Comment

Your email is optional and will only be used to display your name.
Comments are moderated and may take time to appear.

No comments yet. Be the first to share your thoughts!