First you need to have a look here, in order to understand how to produce a sendmail.cf
from sendmail.mc
and restart sendmail afterwards.
Now forget virtusertable. We will define a class of usernames which are allowed to receive mail. All the rest will be discarded. To do this we add the following section in sendmail.mc
LOCAL_CONFIG
C{Receive} user1 user2 user3
If you want to define these users in an external file, instead of directly editing your sendmail.mc
, use an F line, instead of a C line:
LOCAL_CONFIG
F{Receive} -o /etc/mail/receive.allow
This way each line in the file /etc/mail/receive.allow
contains a username that is allowed to receive mail. The -o
switch makes sure that sendmail will not complain if the file does not exist.
Now that the users that are allowed to receive mail are defined, we add the following lines next:
LOCAL_RULE_0
R${Receive} $#OK
R${Receive} < @ $=w . > $* $#OK
R$* $#discard $: $1
Do not copy paste the above snippet of code. The left hand side of the code is tab separated from the right hand one. So type it instead. Next follow the instructions for how to compile sendmail.cf
from sendmail.mc
and restart sendmail.
Each time you modify sendmail.mc
in order to add a user, you need to reproduce sendmail.cf
and restart sendmail. If you choose to store allowed users in an external file, each time you modify this file you need to restart sendmail (no need for a new sendmail.cf
).