Use procmail to sort incoming emails

From BubbaWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

This is work in progress!!


Procmail is a versatile program that lets you filter incoming emails and do all sorts of processing on them. Sorting them, forwarding them, using an application to process them etc. I mainly uses it to sort email into folders depending on their origin or destination.

Install procmail

Log into Bubba via ssh and become root.

Issue:

apt-get update
apt-get install procmail

Configure Postfix to deliver incomming email to procmail

Edit the file /etc/postfix/main.cf and add the line:

mailbox_command = /usr/bin/procmail -a $DOMAIN

Configure procmail

For each user that receives email create the config file /home/"user"/.procmailrc with something like:

# Set to on for debug
VERBOSE=off

DEFAULT=$HOME/Mail/
MAILDIR=$HOME/Mail
PMDIR=$HOME/.procmail
LOGFILE=$PMDIR/procmail.log

INCLUDERC=$PMDIR/rc.filters

Make sure that this file has proper permissions. Otherwise procmail wont touch it.

chmod 0600 ''/home/"user"/.procmailrc''

(Todo, should DEFAULT & MAILDIR perhaps be moved to postfix config?)

Then create the procmail directory associated with this

mkdir /home/"user"/.procmail

Finally set up any filter rules needed. As an example, put all incomming emails from ernie@example.com into the folder ernie edit the file /home/"user"/.procmail/rc.filters and add the following lines:

:0:
* ^From ernie@example.com
.ernie/

Restart postfix

To finnish everything off and start using procmail restart postfix

/etc/init.d/postfix restart

Now all emails comming from ernie would end up in a subfolder to the inbox called ernie. All others should still end up in your inbox.

You can read more on procmail on its homepage www.procmail.org/

Example filters

To be written