Server Side Mail Filtering with Dovecot and Procmail

Dovecot and Procmail Filtering
Ever wanted to do server side mail filtering without adding a bunch of extra programs to the server? With Dovecot deliver and a .procmailrc you can. This does depend on the environment you are using, clearly you must be using Dovecot for IMAP or POP3 and procmail as you LDA (Local Delivery Agent). If you are not using these you should probably try googleing your LDA and Dovecot.

I'm not going into the details of installing these apps and I'm only talking about my setup, well, the setup that works on my server (which also has spamassassin installed) so lets just get on with it.

EDITOR = your favourite editor, emacs, vi, nano.

First create a .procmailrc and setup some basic assignments:

EDITOR $HOME/.procmailrc
DELIVER="/usr/libexec/dovecot/deliver" (should point to your copy of the deliver program!)

Once that is done we can pipe stuff to $DELIVER. Now we need to add some recipies. Recipies require an knowledge of regular expression, again, I'm not going into the details of this here. If you are here you probable already know enough about REGEXP to get by! So lets add a recipe to send all mails less than 25600 bytes to spamassassin.

:0fw: spamassassin.lock
* < 256000
| /usr/bin/spamassassin

Now all messages less than 25600 bytes will go through spamassassin! I trust spamassassin completely having monitored its performance for weeks so I dump eveyting its marked as spam to the null device:

:0
* ^X-Spam-Flag: YES
/dev/null

:0
* ^Subject: \*\*\*SPAM\*\*\*
/dev/null

To filter messages into POP3 or IMAP folders use a recipe like this:

:0
* ^From: .*steve.*
| $DELIVER -m Steve (Steve is a case sensitive name of a mail folder)

As you can see its actually quite easy to setup providing you have the right software installed!

 

Comments


On Tue, 16 Nov 2010 11:11:37 +0000 Wow though we needed to know:
That easy eh?

----

Add Comment


Poster Name / Handle / Email:

Comment

Add the words "cat cow"