Self-Hosted Email That Actually Works: The Ultimate Guide to Digital Sovereignty

The CyberSec Guru

Updated on:

Self-Hosted Email That Actually Works

If you like this post, then please share it:

Buy me A Coffee!

Support The CyberSec Guru’s Mission

🔐 Fuel the cybersecurity crusade by buying me a coffee! Why your support matters: Zero paywalls: Keep the main content 100% free for learners worldwide.

“Your coffee keeps the servers running and the knowledge flowing in our fight against cybercrime.”☕ Support My Work

Buy Me a Coffee Button

In the previous posts of this series, we built the foundation of your sovereign cloud. We’ve established a hardened network, a custom router, and a powerful server environment. Now, we arrive at the most challenging and perhaps most rewarding – milestone: Self-Hosted Email.

Email is the skeleton of your digital identity. It is the recovery method for your bank accounts, the username for your social media, and the record of your private communications. Currently, the vast majority of the world’s email is controlled by two or three massive corporations. This is a systemic risk to privacy and personal freedom.

However, “Email is hard” is the common refrain in the self-hosting community. People say you will get blacklisted, your mail will never arrive, and you’ll spend your life fighting spam filters. This guide is here to prove them wrong. We are going to build an email system based on the philosophy – one that is robust, private, and, most importantly, actually works.

Sovereign Cloud Email Hosting
Sovereign Cloud Email Hosting

The Hard Truth: The “IP Reputation” Trap

Before we touch a single line of code, you must understand why self-hosted email often fails. It comes down to IP Reputation. Spam filters at Gmail, Outlook, and Yahoo are aggressive. They look at the “birthplace” of an email – the IP address of the server that sent it. If that IP address comes from a residential block (like your home internet) or a cheap VPS provider, it is often flagged as “dirty” by default.

Historically, self-hosters tried to send mail directly from their home servers. This almost always results in the “black hole” effect: your email is accepted by the recipient server but never appears in their inbox or even their spam folder.

The Solution: The Hybrid Approach

To solve this, we use a hybrid model. We host the storage, the UI, and the receiving (IMAP/POP3) capabilities on our own sovereign hardware. But for sending (SMTP), we use a “Relay” service with a high reputation. This ensures that while we own our data, our messages are delivered with the authority of a trusted sender.

Choosing Your Software – Why Mailcow?

There are many mail server suites: iRedMail, Mail-in-a-Box, Postfix-from-scratch. But for the Sovereign Cloud, we recommend Mailcow: Dockerized.

Mailcow is a complete, modern mail-in-a-box solution that runs in Docker containers. It includes:

  • Postfix: The mail transfer agent.
  • Dovecot: The IMAP/POP3 server.
  • SOGo: A beautiful webmail interface with calendar and contact support.
  • Rspamd: A powerful, learning spam filter.
  • ClamAV: Antivirus scanning.
  • ACME: Automatic SSL certificates via Let’s Encrypt.

It is modular, easy to update, and handles the “heavy lifting” of configuration automatically.

Hardware Requirements

Do not skimp on resources here. Mailcow runs many services simultaneously.

  • RAM: 6GB Minimum (8GB+ recommended).
  • CPU: 2 Cores (4 Cores for better performance during virus scanning).
  • Storage: Depends on your needs, but SSDs are mandatory for database performance.
Mailcow Architecture
Mailcow Architecture

Preparing the Environment

In Module 2, we set up your Ubuntu VM. Mailcow will live in its own dedicated VM (The “Productivity VM”).

Update and Install Docker

Ensure your VM is ready:

sudo apt update && sudo apt upgrade -y
sudo apt install curl git tar -y

Install Docker using the official convenience script:

curl -sSL [https://get.docker.com/](https://get.docker.com/) | sh
sudo usermod -aG docker $USER

Set the Hostname

Your mail server needs a Fully Qualified Domain Name (FQDN). Usually, this is mail.yourdomain.com.

sudo hostnamectl set-hostname mail.yourdomain.com

Installing Mailcow

Now we fetch the Mailcow files and generate the configuration.

cd /opt
sudo git clone [https://github.com/mailcow/mailcow-dockerized](https://github.com/mailcow/mailcow-dockerized)
cd mailcow-dockerized
sudo ./generate_config.sh

During configuration:

  • Use your FQDN (e.g., mail.yourdomain.com).
  • Choose the “Stable” branch.
  • Set a strong administrative password.

Once generated, pull the images and start the containers:

sudo docker compose pull
sudo docker compose up -d
Mailcow Installation
Mailcow Installation

The DNS Masterclass (SPF, DKIM, DMARC)

This is where 90% of self-hosted email fails. You must prove to the world that you are who you say you are. You do this through three critical DNS records.

SPF (Sender Policy Framework)

SPF is a list of IPs and domains allowed to send mail on behalf of your domain.

  • Type: TXT
  • Value: v=spf1 mx a include:spf.mtasv.net -all (Note: We include Postmark’s SPF here, as they will be our relay.)

DKIM (DomainKeys Identified Mail)

DKIM adds a digital signature to your emails. Mailcow generates this for you.

  • Go to the Mailcow UI (https://mail.yourdomain.com).
  • Navigate to Configuration > DNS Records.
  • Copy the public key for your domain.
  • Create a TXT record in your DNS provider (Cloudflare, etc.) with the selector provided (usually dkim).

DMARC (Domain-based Message Authentication, Reporting, and Conformance)

DMARC tells recipient servers what to do if SPF or DKIM fails.

  • Type: TXT
  • Host: _dmarc
  • Value: v=DMARC1; p=quarantine; rua=mailto:admin@yourdomain.com (Start with p=quarantine until you are sure everything works, then move to p=reject.)
Three Pillars of Email Trust
Three Pillars of Email Trust

The SMTP Relay (The Secret Sauce)

As discussed, sending mail directly from your home IP is a recipe for disaster. We will use Postmark as our relay. Why Postmark? Because they have the highest deliverability standards in the industry and a generous free tier for personal use.

Create a Postmark Account

Sign up and verify your domain. Postmark will ask you to add additional DNS records to prove ownership.

Configure Mailcow to use the Relay

Mailcow makes this easy through the “Sender-Dependent Transports” feature.

  1. Log in to Mailcow as admin.
  2. Go to Configuration > Routing.
  3. Under Sender-Dependent Transports, click Add.
  4. Host: smtp.postmarkapp.com:587
  5. Username/Password: Use your Postmark Server API Token.
  6. Under Domain Settings, ensure your domain is set to use this transport for outgoing mail
Postmark Mailcow Configuration
Postmark Mailcow Configuration

Reverse DNS (PTR)

While the relay handles outgoing mail, your server still needs a PTR record for incoming mail and general server reputation.

A PTR record is the “opposite” of an A record. It maps an IP address back to a hostname. You usually set this through your VPS provider or ISP. If your IP is 1.2.3.4, the PTR record should resolve to mail.yourdomain.com.

Without this, many servers will reject your mail before it even hits the spam filter.

Testing Your Sovereignty

You’ve built the castle. You’ve paved the road. Now, let’s see if the messengers can get through.

The “Mail-Tester” Gauntlet

Go to mail-tester.com. They will give you a unique email address. Send a test email from your new Mailcow webmail to that address.

What to look for:

  • 10/10 Score: This is your goal.
  • Blacklist Check: Ensure your relay IP (Postmark) isn’t on a list.
  • SpamAssassin Score: Ensure your content isn’t triggering false positives.
Email Deliverability Test
Email Deliverability Test

Long-Term Maintenance

Self-hosting email is not “set it and forget it.”

Updates

Mailcow is updated frequently. To update:

cd /opt/mailcow-dockerized
sudo ./update.sh

Backups

Your email is your life’s archive. Use the Mailcow backup script:

./helper-scripts/backup_and_restore.sh backup all

Store these backups on your ZFS Data Vault (which we will build in Module 5).

Monitoring Rspamd

Log in to the Rspamd UI via Mailcow. It will show you exactly why certain emails were flagged as spam. You can “train” it by moving emails in and out of your Junk folder in SOGo.

Freedom of the Inbox

Congratulations. You have achieved what many technical experts say is impossible: you have a self-hosted email server with 100% deliverability.

By following this roadmap, you have:

  1. Reclaimed your digital identity from Google/Microsoft.
  2. Ensured your data is stored on hardware you own.
  3. Built a system that bypasses the “IP Reputation” trap using a trusted relay.

In the next post, we will dive into the pfSense Firewall, ensuring that your new mail server is perfectly protected from the scanners and bots of the open internet.

Welcome to the Sovereign Cloud.

Buy me A Coffee!

Support The CyberSec Guru’s Mission

🔐 Fuel the cybersecurity crusade by buying me a coffee! Your contribution powers free tutorials, hands-on labs, and security resources.

Why your support matters:
  • Writeup Access: Get complete writeup access within 12 hours
  • Zero paywalls: Keep the main content 100% free for learners worldwide

Perks for one-time supporters:
☕️ $5: Shoutout in Buy Me a Coffee
🛡️ $8: Fast-track Access to Live Webinars
💻 $10: Vote on future tutorial topics + exclusive AMA access

“Your coffee keeps the servers running and the knowledge flowing in our fight against cybercrime.”☕ Support My Work

Buy Me a Coffee Button

If you like this post, then please share it:

Discover more from The CyberSec Guru

Subscribe to get the latest posts sent to your email!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from The CyberSec Guru

Subscribe now to keep reading and get access to the full archive.

Continue reading