This arcticle desribes how we can implement custom mail filtering in a plesk9 server having postfix as the MTA. This can be used for mailfiltering tasks like moving over spam messages to a spam or .Spam folder at delivery time etc.This is only a single use that i have described here..but you can devise do any filtering that you can do with the procmail Mailfilter and its filtering language on a per mail account basis
WARNING: you will replace the custom plesk virtual mail delivery agent..and in turn lose all abilities to manage spam filtering and other mail related functions like grouping from the plesk web interface. Attempt this only if you dont have problems managing things from the commandline.Please backup /etc/postfix folder before you attempt this!
================
1. Change the default virtual transport that is called whenever a mail for a virtual user has to be delivered
postconf -e "virtual_transport = procmail"
postconf -e "procmail_destination_recipient_limit = 1"
2. Define the procmail transport in master.cf as below.Please note it is a single line!
procmail unix - n n - - pipe flags=RO user=popuser argv=/usr/bin/procmail -t -m USER=${user} RECIPIENT=${recipient} /etc/postfix/procmailrc.common
3.Create /etc/postfix/procmailrc.common with following content:
========
:0
* RECIPIENT ?? .*@\/.*$
{ DOMAIN = "$MATCH" }
#added RECIPIENT variable and we extract domain name
HOME="/var/qmail/mailnames"
MAILDIR="$HOME/$DOMAIN/$USER/Maildir"
DEFAULT="$MAILDIR/"
#each user will set his own log file
VERBOSE=ON
LOGFILE="/var/log/procmail/proclog-$USER-$DOMAIN"
NL="
"
WS=" "
SWITCHRC="$HOME/$DOMAIN/$USER/.procmailrc"
=======
Enable logging only in the initial phase for troubleshooting ease.Once you find everything is working as intended.Comment out verbose and logging in the above file
Thats it!. no you can define a per user procmail filter at each users mail account in the file .procmailrc
eg: /var/qmail/mailnames/gnusys.net/anoop/.procmailrc
Here is a sample .procmailrc that i used to get spam mails moved into .Spam folder
=====
# send mail through SpamAssassin
:0 fw
* < 256000
| /usr/bin/spamassassin
#filter
:0 H
* ^X-Spam-Status:.*Yes
.Spam/
=====
Problems in this.Contact me at anoop[at]gnusys[dot]net
Tags: plesk, postfix.procmail








January 15th, 2009 at 4:32 pm
Hey this is nice, but is there a way to de exactly the same with 1 central config for multiple (all) users?
January 15th, 2009 at 4:38 pm
That would be very easy change the line
======
SWITCHRC=”$HOME/$DOMAIN/$USER/.procmailrc”
======
to
======
SWITCHRC=”/etc/.procmailrc”
======
And you are done
August 5th, 2009 at 2:55 pm
Hi,
Working like a charm indeed, but unfortunately this way all the default behavior defined by PLESK and written in .qmail files are ommited. (like forwarding)
Is there a way to make postfix run both the procmail and those default rules?
Thanks,
akos
February 25th, 2010 at 2:47 am
Commonly, teachers are willing to analyse the essay papers writing ability of some their students, nevertheless not all students can to write professionally because of lack of knowledge or other stuff. Therefore, a essay writing service is able help to write the term paper professionally.
March 5th, 2010 at 4:04 am
[...] DV3 Server, I had been relying on email clients to move spam-tagged emails into a Junk folder.Custom mail filtering in plesk9 postfix | GNUSYS Knowledge BaseThis arcticle desribes how we can implement custom mail filtering in a plesk9 server having postfix [...]
March 20th, 2010 at 4:13 am
[...] chgrp popuser .qmail chmod 600 .procmailrc chown popuser .procmailrc chgrp popuser .procmailrc …Custom mail filtering in plesk9 postfix | GNUSYS Knowledge BaseThis arcticle desribes how we can implement custom mail filtering in a plesk9 server having postfix [...]
April 7th, 2010 at 4:45 pm
Awesome post as always, thanks for writing so much helpful stuff on a regular basis.
April 8th, 2010 at 8:36 am
thanks share your artic!
May 26th, 2010 at 2:11 pm
Awesome weblog you have here. Bookmarking now!
May 29th, 2010 at 3:28 am
To the point and an excellent write-up.
June 10th, 2010 at 8:12 pm
I definetelly will be visiting it again.
June 24th, 2010 at 7:04 pm
Really nice post!