Insist On Valid Host Name In MAIL FROM: Command
Problem: You want to reject mail that has bogus host names in the MAIL FROM: SMTP command. (Also includes the previous fix, but modified so that it will deliver an insulting message back to the perpetrators.)
Solution: Check for validity in the MAIL command. In this case you have to permit people in the spammers database greater access to your server (e.g., they will be able to use VRFY and EXPN), but you can still prevent them from sending mail.
Warning: This ruleset is incompatible with the DeliveryMode=defer option, since it requires that a DNS lookup be done immediately upon mail receipt.
Code: (Downloadable version)
Kspammers hash /etc/spammers
Scheck_mail
# check for valid domain name
R$* $: <?> $>3 $1
R<?> $* < @ $+ . > $: <OK>
R<?> $* < @ $+ > $#error $: 451 Domain must resolve
# check relay against spammers database
R$* $: $(spammers $&{client_name} $: OK $)
ROK $@ OK
R$+ $#error $: 551 $1
Notes:
VRFY, EXPN, etc. will still work. Since it keys off the MAIL FROM: value, which is easily forged, it may be less effective than the previous solution.
/etc/spammers is a database map and must be created with: makemap hash /etc/spammers < /etc/spammers
In 8.9, unresolvable domains are rejected by default. Also, in 8.9, the /etc/spammers checks are replaced by the FEATURE(access_db).