Use procmail to sort incoming emails

From BubbaWiki
Jump to navigation Jump to search

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.


apt-get update
apt-get install procmail

Configure Postfix to deliver incomming email to procmail

Edit the file /etc/postfix/ 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



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 into the folder ernie edit the file /home/"user"/.procmail/rc.filters and add the following lines:

* ^From

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

Example filters

To be written