指南

一个能够真正到达收件箱的自托管邮件服务器

高级阅读时间 45 分钟更新时间 2026年6月4日
简短回答

安装邮件服务器很容易;但要获得收件方的信任则不然。你需要开放出站端口25、与横幅主机名匹配的PTR记录、正确发布的SPF、DKIM和DMARC、没有垃圾邮件历史的地址空间,以及逐步增加发送量。任何一项遗漏,邮件都会落入垃圾箱。

01 先设置主机名和反向DNS

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 安装技术栈

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 发布 SPF、DKIM 和 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 预热IP地址

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 报告干净后再收紧DMARC

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.

常见问题

为什么我的邮件会进垃圾箱?

按可能性排序:缺失或不匹配的PTR、缺失DKIM、新IP发送过快过多,或地址空间有滥用历史。前三个由你解决;第四个由服务商负责。

我需要静态IP吗?

是的,且要一个能设置反向DNS的。这两个在每台OnionVPS实例上都是标准配置。