Topics

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 using the 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
D{Email}@.com
D{}www
D{}root

SCheckTo
R${www}							$@ OK
R${}							$@ OK
R$*@gadelkareem.com		$@ OK
R${Email}		$@ OK
R$*	$#error $: 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 submit.cf here is because of the fact I do not use sendmail to recieve any emails, however if you like to do the block from the outside you can use sendmail.cf to do the job.

  • ray

    working for me..thx 😉

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

    Thank you.

    John M