home January 01, 2017

procmail config


procmailrc example

Procmail is the program you can use the filter emails into different mail boxes and do actions on delivered emails.

Below is an example of a usable .procmailrc config file. You can cut and paste this example into your .procmailrc file without issue. The config includes the lines one could use with bogofilter, a Bayesian spam filter. I highly suggest using bogofilter because it is easy to use and configure. For more information on bogofilter look on / and check for the bogofilter link.

#########################################
########  .procmail rules  ##############
#########################################

### System variables
DROPPRIVS=yes
LINEBUF=8192
PATH=$HOME/bin:/usr/bin:/global/bin:/usr/ucb:/bin:/usr/local/bin:
SHELL="/bin/sh"

### De-bugging logs
#VERBOSE=yes
#LOGABSTRACT=all
LOGFILE=$HOME/procmail.log

### Mail Folders
MAILDIR =$HOME/Mail
INBOX =$MAILDIR/inbox
ARCHIVE =$MAILDIR/archive
SPAM =$MAILDIR/SPAM
LISTS =$MAILDIR/lists 

############################################
######### Procmail Filters  ################
############################################

### Check for duplicates
:0 Wh:dup
 | formail -D 102400 $MAILDIR/dups.msgid.cache 

### Setting Date: to date recieved 
:0f
  | formail -I "Date: `date '+%a, %d %b %Y %R:%S %z'`"

### Mailing lists to a unified mailbox
:0
  *^Received:.*(mailing_list_one\.org|mailing_list_two\.com)
  ${LISTS}

### Mail delivered to me ###
:0 
  {
   :0fw
     | /usr/local/bin/bogofilter -p -e
   :0
     *^X-Bogosity:.(Spam|Yes)
     ${SPAM}
   :0
     *^X-Bogosity:.(Ham|Unsure|No)
       {
        :0 c
          *^(To:|Cc:).*(username.*@|root@)
           ${ARCHIVE}
        :0 
          ${INBOX}
       }
  }

What does it all mean?

Take a few miniutes and look at the config file and make sure you understand what it is doing before using it. This .procmailrc file has the basics to filter out mailing list and spamd and then place the rest of your mail in a default inbox. A few lines to take a closer look at are as follows:

De-bugging logs areaThese are the options you can enable if you are having problems with your procmail rules and the mail is not being filtered properly.

Mail Folders areaThis is where you need to set the variables locating your mail folders. There are a few examples to get your started.

Check for duplicates areaThis is a rule to look at the message id of the email and not to deliver more than one copy of it. This is handy if you are one a few mailing lists in which the same email is sent to both lists. You really do not need two(2) copies, so this rule will deliver only the first to arrive and /dev/null the second.

Mailing lists to a unified mailbox area Mailing lists from all domains we are expecting mailing lists from will be put into the LISTS mailbox.

Mail delivered to me area This is the final step for email. Here the email is run against the external program "bogofilter" and we check the "X-Bogosity" header to see if the mail is considered spam or not. If it is then we make a copy and place it into an ARCHIVE folder as well as put a copy in the INBOX mailbox.

HELPFUL HINT: For an added layer of protection again spam you can use a bayesian spam filter. Check out our Bogofilter "how to" Anti-Spam Guide. With a little time and understanding you could easily filter up to 99% of any remaining spam.