2026-11-28 Infrastructure & Self-Hosting Draft

Self-Hosting Mail With Dual Edge Relays, Rspamd & Cyrus IMAP

Sanitized architectural notes on running a self-hosted email stack from both external and internal viewpoints — covering redundant edge relays, anti-spam/antivirus filtering, DKIM/SPF/DMARC, and isolated internal storage.

Draft Note: This post outlines the sanitized architecture behind my self-hosted email stack. Private domains, IP addresses, hostnames, account names, and exact filtering thresholds are intentionally omitted.

Why Split Edge Mail Relays From the Internal Mail Store?

Exposing a full mailbox server directly on the public internet concentrates authentication surfaces, spam processing, and user data on one host. Splitting the architecture into stateless edge MX relays and an isolated internal mail store gives cleaner security boundaries and better deliverability:

  • Mailbox isolation: The mail store (Postfix + Cyrus IMAP) lives strictly inside the private network with zero inbound internet ports exposed directly to it.
  • Redundant MX ingress & clean outbound reputation: Two geographically separate edge relays share MX priority, maintain matching forward/reverse DNS (PTR) and TLS certificates, and handle all public SMTP traffic.
  • Before-queue defense-in-depth: Spam, virus, and recipient checks run before messages are accepted at SMTP time and before anything crosses the encrypted VPN transit backbone.

End-to-End Mail Flow

[Public Internet Senders / Remote MX]
   ▲
   │  SMTP + opportunistic STARTTLS (TCP 25, IPv4 & IPv6)
   ▼
[Dual Edge Mail Relays (Postfix + Rspamd + Valkey + ClamAV)]
   │  • Before-queue DNSBL, SPF/DKIM/DMARC, Bayes, greylisting & AV scan
   │  • Outbound: 2048-bit RSA DKIM signing + internal header scrubbing
   ▲
   │  Encrypted VPN + OSPF transit backbone
   ▼
[Internal Mail Server (Postfix + ClamAV Milter + Cyrus IMAP)]
   ▲                                       ▲
   │  Loopback-only null clients (LAN)     │  Encrypted MUA submission (465/587) & IMAPS (993)
[Homelab Servers & Routers]             [Mail Clients]

1. External Viewpoint (Internet Ingress, Delivery & Reputation)

From the perspective of remote mail servers, all mail enters and exits solely through the two public edge relays:

  • Dual Edge MX Relays & Transport Security: Both edge relays accept public SMTP over IPv4 and IPv6 with opportunistic STARTTLS (TLS 1.2+) backed by automated Let’s Encrypt ECDSA certificates and aligned forward/reverse DNS (PTR) records.
  • SMTP-Time Protocol & Recipient Hygiene: Edge Postfix enforces strict HELO/EHLO syntax and valid sender domain DNS checks, disables VRFY to prevent address enumeration, and runs dynamic recipient verification — probing the internal mail server and caching results locally so unknown addresses are rejected (550) during the SMTP handshake without generating backscatter bounces.
  • Outbound Authentication & Header Scrubbing: Every served domain publishes SPF (covering both apex senders and edge relay HELO identities), DMARC, and DNSSEC (ECDSA P-256) records. Outbound mail is signed by Rspamd using shared 2048-bit RSA DKIM keys synchronized across both relays, while outbound transport PCRE header checks strip private-network/loopback Received: hops and internal X-Virus-*/X-Spam-* headers before final delivery (inbound relays leave external headers intact for downstream inspection).

2. Anti-Spam & Anti-Virus Defense-in-Depth

Filtering happens before-queue during the live SMTP transaction so unwanted or malicious mail is rejected back to the sender rather than silently dropped or quarantined after acceptance:

  • Before-Queue Edge Filtering (Rspamd + Valkey): Every inbound message is evaluated by Rspamd using SPF/DKIM/DMARC checks, DNSBL/RBL reputation lookups, URL and MIME heuristics, Bayesian classification, and stateful greylisting backed by Valkey. Lookups are routed through dedicated private recursive DNS resolvers instead of shared hosting resolvers so DNSBL queries avoid third-party rate limits. Tiered SMTP-time actions greylist borderline senders, tag suspect messages with authentication/spam headers, and reject high-confidence spam outright before it reaches the internal network.
  • Two-Stage Antivirus Scanning (ClamAV): Edge relays scan MIME attachments via clamd inside Rspamd and reject infected payloads at SMTP time. Independently, the internal mail server runs its own before-queue clamav-milter so mail submitted internally is scanned as well. Both tiers run automated signature updates (freshclam) and fail safe with temporary deferral (tempfail) if a scanner is momentarily unavailable.

3. Internal Viewpoint (Mail Store, Submission & Homelab Relays)

Inside the private network, storage, user authentication, and automated system alerts stay strictly separated from public SMTP exposure:

  • Isolated Mail Store (Postfix + Cyrus IMAP): Accepted inbound mail is handed over a chrooted local LMTP Unix socket to Cyrus IMAP, which consolidates multiple domain aliases into a clean shared mailbox namespace with IMAPS, server-side Sieve filtering, periodic squatter full-text indexing, and CalDAV/CardDAV.
  • Authenticated Submission & Trust Boundaries: Mail clients submit exclusively over encrypted submission ports (587 mandatory STARTTLS or 465 implicit TLS) with SASL authentication (noanonymous); authentication is disabled on port 25. Explicit trust-boundary exclusions prevent proxied edge traffic from being treated as trusted internal relay traffic.
  • Internal Null-Client Relays & Failover Outbound: Homelab servers and routers run loopback-only Postfix null clients that refuse external connections and forward cron/system alerts cleanly to the internal mail server. Outbound internet mail flows over the encrypted VPN to the primary edge relay with automatic failover to the secondary relay.
  • Observability: Postfix queue depth, Rspamd scan/greylist/reject counters, Valkey state, ClamAV signature freshness, and centralized mail logs are collected continuously into Prometheus, Alertmanager, Grafana, and Loki.
Questions or feedback?

Reach out at plopli@plopli.eu or browse CAD/KiCad work on GitHub (@Plopli).