General
cancel
Showing results for 
Search instead for 
Did you mean: 

Restrict who can send mail to a specific user

Restrict who can send mail to a specific user

I'd like to set up a special alias on my system and have only specific email addresses be able to send mail to it. Any mail sent from an "unauthorized" email address would be returned or ignored.
Can this be done?
Thanks in advance,
mike
4 REPLIES
Craig Rants
Honored Contributor

Re: Restrict who can send mail to a specific user

Depends on what version you are running. 8.9.3 provides much greater function as far as blocking emails for relaying and such.

You may have to generate a new sendmail.cf file. You can do this by running the /usr/newconfig/etc/mail/cf/cf/gen_cf script to add in the specific function you are looking for.

Good Luck,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
harry d brown jr
Honored Contributor

Re: Restrict who can send mail to a specific user

It can be done in sendmail - It's time for you to break out the sendmail manual - something I never want to look at again --- ouch!

live free or die
harry
Live Free or Die
Marco Paganini
Respected Contributor

Re: Restrict who can send mail to a specific user

Hello,

The easiest way (and it doesn't involve messing around with sendmail.cf) is to install procmail and use a rule in .procmailrc + a suitable .forward file. You can download procmail from:

http://hpux.ee.ualberta.ca/hppd/hpux/Networking/Mail/procmail-3.21/

Suppose your user is called foobar. Go to foobar's home directory and create a .forward file like:

"|exec /opt/procmail/bin/procmail"

(please check the correct location for procmail)

Next, create a .procmailrc file with the following contents:

:0:
* FROM .*unwanted_user@unwanted_domain.com
/dev/null

Substitute unwanted_user and unwanted_domain for the appropriate ones.

All messages coming from these users will be completely discarded. Repeat the entire block if you want to add another 'unwanted' user.

Procmail is very powerful. Make sure you consult procmail's documentation (man procmail, man procmailrc and man procmailex) if you want to do something more complex (like bouncing the message to the sender with an error indication).

Regards,
Paga
Keeping alive, until I die.
Frank Slootweg
Honored Contributor

Re: Restrict who can send mail to a specific user

Adding to Marco's excellent comments about using procmail:

It is often easier not to say what you do not want, but to say what you do want.
This is 'strangely' enough done most effectively with the "!" (not) operator, i.e. saying if it is not something you want, then you don't want it.

Confusing/confused? Let me give a simple example from my .procmailrc:

* !(^To:.*|^Cc:.*|^From:.*)(franks@support|franks@neth|frank_slootweg|franks.$|news.$|tineke.slootweg)

This mean that if a message is NOT To: or Cc: or From: any of the listed names, I don't want it. So, for *example*, mail which is not *addressed* to me, but is *sent* to me, gets dropped. This takes care of most 'spam' (UCE).

procmail can do anything you like with the "I don't want it" category, i.e. drop it, file it, return it, return an error, shutdown the system :-), whatever.