Configure sendmail to accept emails only if “from”, “to” or specific field matches

you can an email address or even a host that is spamming you the access located in your etc directory, the bad news is that it does not support regex or even wildcards.
What I needed to achieve is disabling all outgoing mail unless the To: field matches some email…’s how to do that:
edit you .cf file in your /etc/mail dir

HHeader: $>Ruleset

HTo: $>CheckTo

R${}							$@ OK
R${root}							$@ OK
R$*		$@ OK
R${Email}		$@ OK
R$*	$# $: 552 Ha2aw aw aw..... TOZ!

HCc: $>CheckTo

so any message going to another mail would be blocked and sent to postmaster with that error “552 Ha2aw aw aw….. TOZ!”
you can use regex as long as you follow manual.
the use of here is because of the fact I do not use sendmail to recieve any emails, however if you like to do the from the outside you can use to do the job.

  • ray

    working for me..thx 😉

  • Can we edit file to do like that ?
    If I edit manually, when I rebuild from I need to edit again.

    Thank you.

    John M