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 file located in your etc directory, the bad news is that it does not support 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${www}							$@ OK
R${}							$@ 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 sendmail 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 world you can use to do the job.