Guide

A self-hosted mail server that actually reaches the inbox

Advanced45 min readUpdated June 4, 2026
Short answer

Installing a mail server is easy; being trusted by receivers is not. You need outbound port 25, a PTR record matching your banner hostname, SPF, DKIM and DMARC published correctly, address space with no spam history, and a gradual volume ramp. Miss any one and mail lands in spam.

01 Set the hostname and reverse DNS first

Do this before installing anything. The PTR must resolve to the hostname the server announces, and that hostname must have a forward record pointing back to the same address.

hostnamectl set-hostname mail.example.com
# then set the PTR to mail.example.com in the OnionVPS panel

02 Install the stack

Mailcow gives you a complete Docker-based stack. Stalwart is a single Rust binary if you prefer fewer moving parts.

git clone https://github.com/mailcow/mailcow-dockerized /opt/mailcow
cd /opt/mailcow && ./generate_config.sh
docker compose up -d

03 Publish SPF, DKIM and DMARC

All three are DNS records. DKIM keys are generated by the mail stack; copy the public key from its admin interface.

example.com.            TXT  "v=spf1 mx -all"
dkim._domainkey        TXT  "v=DKIM1; k=rsa; p=MIGfMA0..."
_dmarc                 TXT  "v=DMARC1; p=none; rua=mailto:[email protected]"

04 Warm the address up

A few dozen messages a day for the first week, then roughly double weekly. A volume spike from a new IP is indistinguishable from a compromised host, and receivers treat it accordingly.

05 Tighten DMARC once the reports are clean

Read aggregate reports for a fortnight at p=none, fix whatever is failing, then move to p=quarantine and eventually p=reject. Going straight to reject reliably breaks systems you forgot were sending mail.

Frequently asked questions

Why is my mail going to spam?

In order of likelihood: missing or mismatched PTR, missing DKIM, a new IP sending too much too soon, or address space with prior abuse history. The first three are yours to fix; the fourth is the provider's.

Do I need a static IP?

Yes, and one you can set reverse DNS on. Both are standard on every OnionVPS instance.