Custom mail filtering in plesk9 postfix

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

Share and Enjoy:
  • Digg
  • Mixx
  • del.icio.us
  • StumbleUpon
  • Facebook
  • TwitThis
  • Technorati
  • Google

Tags: ,

12 Responses to “Custom mail filtering in plesk9 postfix”

  1. azzy Says:

    Hey this is nice, but is there a way to de exactly the same with 1 central config for multiple (all) users?

  2. Anoop Alias Says:

    That would be very easy change the line
    ======
    SWITCHRC=”$HOME/$DOMAIN/$USER/.procmailrc”
    ======
    to
    ======
    SWITCHRC=”/etc/.procmailrc”
    ======

    And you are done :)

  3. Akos B. Says:

    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

  4. custom writing Says:

    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.

  5. procmail log Says:

    [...] 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 [...]

  6. popuser Says:

    [...] 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 [...]

  7. Gregory Despain Says:

    Awesome post as always, thanks for writing so much helpful stuff on a regular basis.

  8. metin2yang Says:

    thanks share your artic!

  9. Web Filters Says:

    Awesome weblog you have here. Bookmarking now!

  10. Darren Ritter Says:

    To the point and an excellent write-up.

  11. health info Says:

    I definetelly will be visiting it again.

  12. shit stained cumballs Says:

    Really nice post!

Leave a Reply