The need for doing this suggests you are not implementing the existing email spoofing controls that would protect your domain from abuse globally, and that you are using the same smtpd
instance for inbound & outbound mail.
The proper solution for this would include:
- Deploying DKIM & SPF.
- Deploying a DMARC policy with
p=reject
.
- Configuring OpenDMARC on the host for rejecting inbound, forged mail.
- Using a separate
smtpd
instance as a submissions (smtps
) for outbound mail.
If you started from the #4, you could already use the header_checks
as you suggest, but that would became unnecessary after you are finished with #1, #2 & #3.
Protecting the envelope sender from spoofing would be possible by allowing mail from trusted IP addresses and then rejecting the sender domain for the rest.
A solution with hash:
(Berkeley DB) table type:
smtpd_recipient_restrictions =
. . .
permit_mynetworks,
check_sender_access hash:/etc/postfix/access/sender_access,
permit
And in the /etc/postfix/access/sender_access
:
example.com 550 YOU ARE NOT ME.
This requires running postmap /etc/postfix/access/sender_access
after modifications!
Another solution requires the Postfix PCRE Support, but is more flexible, as it enables, e.g., blacklisting entire TLDs.
smtpd_recipient_restrictions =
. . .
permit_mynetworks,
check_sender_access pcre:/etc/postfix/access/sender_access,
permit
And in the /etc/postfix/access/sender_access
:
/example\.com$/ 550 YOU ARE NOT ME.
/\.loan$/ 550 .loan? no thanks, we have money.