How do I set up a email whitelist using only procmailrc to protect my kids from unwanted email?

I currently us the OS parental controls, but that is only good for the computer it is enabled on.

I understand that as my kids grow up, they'll figure out work arounds to any technical parental restrictions imposed upon them, but I want to at least understand the options that I have until then.

  • I've done this for sending reminders to my phone - I'll post the recipe when I can ssh to my server :)
    – warren
    Commented Sep 14, 2009 at 12:33
  • added the whitelist recipe as promised :)
    – warren
    Commented Sep 16, 2009 at 12:59
  • Nice stuff. I'll have to try this out as well.
    – pave
    Commented Sep 16, 2009 at 13:07

4 Answers 4


procmail can filter by the From header, and there are many recipe examples.

# This one discards all mail sent from the address below.
* ^From: [email protected]

But don't forget that procmail only works with locally delivered mail. It won't affect mailboxes accessed over IMAP or webmail.

  • This is a blacklist recipe. Do you know how to do it the opposite? Such as only allow mail from certain addresses.
    – hanleyp
    Commented Sep 5, 2009 at 16:59
  • 1
    Just change the recipe to use ${DEFAULT} as the mailbox, then add a second recipe that routes the rest to /dev/null. Commented Sep 6, 2009 at 8:07
  • @RoninTom's answer is simpler and more to the point.
    – tripleee
    Commented May 17, 2013 at 8:10

The one I use to send messages from myself to my phone:


# if it comes from a specific address(es), send to my cell
# it's be just as easy to whitelist a domain by adding another `|domain.tld` section to the bracketed regex
* ^From.*[main.email.domain.tld|other.email.domain.tld]
* ^To.*datente
! [email protected]

# push everything else to my normal user
* .
! mainuser
  • also note: I intentionally only gather email sent to the one domain, not any others hosted on the same server
    – warren
    Commented Sep 18, 2009 at 5:23

I think we have not any solution yet, that exactly solves the initial problem. Therefore, I would like to provide a more explicit approach. Lets suppose, that our whitelist looks like this:


Then I would try the following reciept:

* !^From.*@white\.domain\.tld
* !^From.*@light\.domain\.tld

This would send all emails that are not from [email protected] and not from [email protected] to /dev/null. The remaining emails are send to the default destination. Be aware to use \. in your pattern if you like to match a single dot. The pattern . matches a single character.

If you have a short whitelist, you could try to get an even shorter reciept by combining the patterns:

* !^From.*@(white|light)\.domain\.tld

Be aware to use ( ) here. Using [ ] would be a mistake.


I'm not at all sure where I got this from (I know I didn't write it myself), but I've been using it in a .procmailrc for a while now to forward only messages from an address listed in a separate whitelist file to a given target email address:

PMDIR=$HOME/Procmail      # Make sure this directory exists!
[email protected]

# allow any addresses listed in $PMDIR/whitelist
FROM_ADDR=`formail -zxFrom: | sed 's/\(.*[^-_\.0-9a-zA-Z]\)\?\([-_\.0-9a-zA-Z]\+@[-_\.0-9a-zA-Z]\+\).*/\2/'`
* ? fgrep -xs "$FROM_ADDR" "$WHITELIST"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .