Postfix policy daemon · MSA / Submission

Catch mistyped recipient domains — and suggest the likely correct one.

PDC checks recipient domains during RCPT TO and gives users an immediate, readable hint when a destination looks wrong — including a likely correction when the intended domain can be identified safely.

No queue parsing No SMTP probing No automatic rewriting MIT licensed
submission
235 2.7.0 Authentication successful
MAIL FROM:<user@example.org>
250 2.1.0 Ok

RCPT TO:<gn@gimail.com>
550 5.1.2 Recipient address rejected:
The recipient domain "gimail.com"
does not have a usable mail exchanger.
Did you mean "gmail.com"?
Why PDC?

Postfix can reject unknown domains. PDC adds the useful part: a plausible correction.

The goal is deliberately narrow: catch obvious recipient-domain mistakes at the MSA while the sender can still correct them immediately.

01

Before the queue

PDC runs as a Postfix policy service during RCPT TO. Broken destinations are rejected before message acceptance.

02

Readable replies

Instead of a later generic MAILER-DAEMON bounce, the sender gets an immediate, understandable SMTP error.

03

Conservative suggestions

A working mail domain is never rejected just because it resembles another domain. Suggestions are considered only after the destination is already known to be unusable.

Decision model

Small rules, predictable behaviour.

DUNNO
Usable MX Destination has a real mail exchanger.
DUNNO
No MX, but usable A / AAAA RFC 5321 implicit-MX fallback remains valid.
550
RFC 7505 Null MX MX 0 . explicitly says that the domain does not accept mail.
550
Unusable MX Examples: localhost, loopback-only targets, or MX hosts without usable A/AAAA.
550
NXDOMAIN / no usable mail route PDC can additionally suggest a plausible domain from the external reference list.
450
Temporary DNS failure SERVFAIL, unreachable authority or resolver timeout stays temporary.
Fail-open by design: an internal PDC failure returns DUNNO instead of blocking legitimate mail.
Typo detection

A reference list, not a hard-coded provider database.

Canonical domains live in an external domains.txt. PDC reloads it when the file changes, so updates do not require code changes or a service restart.

Matching is intentionally conservative: one substituted, inserted or deleted character, or one adjacent transposition. That also catches simple TLD mistakes such as kabelmail.co → kabelmail.com.

domains.txt
gmail.com
outlook.com
gmx.de
web.de
kabelmail.com
t-online.de
proton.me
Installation

Minimal dependencies. Native Postfix policy delegation.

1

Install dependency

apt install python3-dnspython
2

Install PDC

mkdir -p /opt/pdc
install -m 0755 pdc.py /opt/pdc/
install -m 0644 domains.txt typo-map.txt /opt/pdc/

master.cf

pdc unix  -  n  n  -  0  spawn
    user=nobody argv=/opt/pdc/pdc.py

main.cf

smtpd_recipient_restrictions =
    reject_non_fqdn_recipient,
    check_policy_service unix:private/pdc,
    permit_mynetworks,
    permit_sasl_authenticated,
    ...
Ordering matters. PDC must run before permit_mynetworks and permit_sasl_authenticated, otherwise those PERMIT results short-circuit the restriction list.
postfix check
postfix reload
DNS efficiency

Do not run the same recipient-domain check twice.

On the MSA path, PDC is intended to replace reject_unknown_recipient_domain, not sit next to it. Postfix does not expose that restriction's DNS result to policy services, so PDC cannot directly reuse it.

PDC asks for MX first. A/AAAA are queried only if no MX RRset exists. A valid MX or Null MX therefore normally needs only one resolver lookup.

Recommended
reject_non_fqdn_recipient,
check_policy_service unix:private/pdc,
permit_mynetworks,
permit_sasl_authenticated
Avoid duplicate checks
reject_non_fqdn_recipient,
reject_unknown_recipient_domain,
check_policy_service unix:private/pdc,
...
Use the same local caching resolver for Postfix and PDC. With Unbound or BIND on localhost, repeated lookups by PDC, Postfix and later smtp(8) delivery attempts are usually cache hits instead of new external DNS traffic.
Logging

Only when PDC actually does something.

Successful recipients are intentionally quiet. PDC logs rejects, defers, configuration errors and internal errors.

pdc: action="reject" sasl="user@example.org" recipient="x@gimail.com" domain="gimail.com" reason="unusable_mx" suggestion="gmail.com"

pdc: action="defer" sasl="user@example.org" recipient="x@broken.example" domain="broken.example" reason="dns_tempfail"
Manual test

Test the policy protocol without sending mail.

Run the daemon interactively and terminate the request with an empty line.

shell
/opt/pdc/pdc.py

protocol_state=RCPT
sasl_username=testuser
recipient=someone@gimail.com

action=550 5.1.2 ... Did you mean "gmail.com"?
Non-goals

PDC deliberately stays small.

No remote SMTP recipient probing No automatic recipient rewriting No queue parsing No log parsing No rejection of working domains by similarity alone No local-host/IP exception database
Open source

PDC is small enough to audit and easy to extend.

Python · Postfix policy delegation · MIT License

github.com/frickl/pdc