One of my biggest beefs with Plesk’s e-mail handling is the lack of server-side filtering. Plesk will only allow you to throw away e-mails marked as spam, but this won’t work for me since SpamAssassin marks some mails as spam that actually aren’t. If you set up filters in SquirrelMail or Horde, the filters will only work if you always log into the webmail interface to snag your e-mail.
Luckily, you can do some fancy work with procmail to have the filtering done server-side.
First, make sure procmail is installed on your server, and change to this directory:
/var/qmail/mailnames/yourdomain.com/yourusername/
Inside that directory, drop in a .procmailrc file which contains the following:
MAILDIR=/var/qmail/mailnames/yourdomain.com/yourusername/Maildir
DEFAULT=${MAILDIR}/
SPAMDIR=${MAILDIR}/.Junk/
:0
* ^X-Spam-Status: Yes.*
${SPAMDIR}
Once that file is in place, move the .qmail file out of the way, and replace it with this:
| /usr/local/psa/bin/psa-spamc accept
|preline /usr/bin/procmail -m -o .procmailrc
Please be aware that these changes will disappear if you make any adjustments to your mail configuration within Plesk. To get around this annoyance, just change the file attributes to immutable:
# chattr +i .qmail .procmailrc
Credit for this trick goes to Russ Wittmann.
14 Comments on “Sort e-mail in Plesk with procmail”
You can track this conversation through its atom feed.
Thanks for this help. I’ve been trying to figure this out for ages, but it’s just one part of a long slew of things I’m wanting to do, but cannot figure out because Plesk has it running differently than what Spamassassin’s docs show. I’ve looked the net over for documentation on the way Plesk does things only to get mile long rants in forums with no help at all. I manage a small dedicated virtual server hosted at Media Temple with just a few websites and will probably have at the most about a dozen emails between the three domains. At the moment most are forwarding mail only to another address.
What I’m wanting to do is setup spamassassin system wide and have a single bayes folder for everything to go into on my server. What I’d like to do is add IMAP folders on every account where there’s a spam folder, mark as spam folder, and a mark as not spam folder.
My idea is to make mail that is marked as spam to be delivered to each of their spam folders just as you have outlined here. If they get a false positive they can drag the mail to the mark as not spam folder. If they get spam in their inbox they can drag those to the mark as spam folder. Daily a cronjob would update the system’s bayes with every mail account’s new spam rules, delete the contents of the mark as spam folder, and move the mail from the mark as not spam folder to their inbox.
Is this even possible to your knowledge? I just need a nudge in the right direction or something. A couple of days of hunting this information down has gotten me burnt out. Thanks in advance and thanks for the help you’ve given me in this post already.
Posted on December 5, 2007 at 1:09 am.
Many thanks for the article, to which I was referred by rackspace support – exactly what I needed! Just wanted to add a quick observation, which was that my plesk install (psa v8.2.1_build82070919.15 os_RedHat el4) seems to be quite well-behaved with regard to the .qmail file if you leave it chattr -i. If you *do* make .qmail immutable, this will prevent users switching autoresponders, redirects (etc) on/off via plesk, but if you leave as it is, plesk seems to simply add/remove the necessary lines from the end of the file, leaving the references to .procmailrc intact at the top.
Thanks again, Tim.
Posted on April 9, 2008 at 2:58 am.
@Khadgar: With Plesk, I’m not sure that this is possible. It sounds like you want your users to be able to mark e-mails as “ham” and “spam”, but Plesk’s SpamAssassin configuration probably won’t allow for it. I’ve seen some other control panels implement SpamAssassin in this way (like DirectAdmin), but you would have to custom-roll something for your Plesk installation.
@tim.howe: You’re welcome! That is a good point – by making .qmail immutable, users in Plesk may try to change settings, but they won’t ever take effect. In fact, Plesk won’t even throw an error when they attempt to make a change! I suggested it in the original post just in case someone might change a setting that would throw out all of your custom changes.
Posted on April 9, 2008 at 8:14 am.
What about when mchk runs? That rebuilds all the .qmail files, and either will drop the changes, or fail if the file is immutable:
“/usr/local/psa/admin/sbin/mchk –with-spam
mchk: Unable to truncate or create file .qmail: Permission denied
System error 13: Permission denied
mchk: Unable to truncate or create file .qmail: Permission denied
System error 13: Permission denied
mchk: Unable to create .qmail file
System error 13: Permission denied
mchk: Unable to create .qmail file
System error 13: Permission denied”
That will leave the qmail system in an inconsistent state, and bork any upgrades.
I find with Plesk it is best to color within the lines.
Posted on June 18, 2008 at 8:22 pm.
@sublime – You’re right. Unfortunately, you have to remove the immutable flag from the file before performing an upgrade. Then you have to put it back once the upgrade is finished.
Posted on June 18, 2008 at 8:24 pm.
Thanks for this article.
I’m trying to sort mail into a server-side mailbox coming from my company’s domain. Would this method work for sorting mail from a given domain?
Posted on July 7, 2008 at 8:03 pm.
This is great.. I have been trying to do this for ages and have never managed to figure it out. Why does plesk not do this out of the box????
thanks again
Posted on September 13, 2008 at 12:33 pm.
The instructions say “move the .qmail file out of the way, and replace it with this….”
I am fairly new to this – what do I call the new file? Should it be called .qmail and include the new contents?
Thank you.
Posted on November 28, 2008 at 9:28 am.
Kim – you are correct. The new file should be called “.qmail”, just like the original one that Plesk created.
Posted on November 28, 2008 at 9:33 am.
One other question, my original .qmail file looked like this:
| /usr/local/psa/bin/psa-spamc accept
| true
| /usr/bin/ deliverquota ./Maildir
&megan@mydomain.com
I’ve replaced it with:
| /urs/local/psa/bin/psa-spamc accept
|preline /usr/bin/procmail -m -o .procmailrc
Where does the forward to my other e-mail go in this replaced .qmail file?
Thank you. These tutorials and help are so much appreciated!
Posted on November 28, 2008 at 10:52 am.
I had implemented procmail filtering for all accounts in plesk9 with postfix as the MTA.Here is the link to the implementation
http://gnusys.net/custom-mail-filtering-in-plesk9-postfix/
Posted on January 1, 2009 at 10:24 pm.
ramblings of the village idiot » Blog Archive » using procmail with plesk says:
[...] http://www.russwittmann.com/2007/07/14/server-side-mail-filtering-using-qmailprocmail-under-plesk/ http://rackerhacker.com/2007/11/27/sort-e-mail-in-plesk-with-procmail/ [...]
Posted on January 6, 2009 at 6:52 pm.
under my plesk9-system this doesnt work anymore – the file psa-spamc, thats been called on is missing … anyone have an idea?
thx in advance
pw
Posted on April 27, 2009 at 8:57 am.
For me the solution above doesn’t work. Firstly, preline was not present at all – I switched from postfix to qmail. From a backup I copied preline, but still no luck – the mail doesn’t get delivered at all, just remains in the queue.
I tried Anoop Alias’ solution which works nicely (changing the transporter from plesk’s to procmail) but that way the .qmail file doesn’t get processed at all, which means forwardings and quotas are broken.
Does anyone have any more ideas how to make both procmail filtering work and keeping the .qmail files and those rules as well?
Regards,
Akos
Posted on August 6, 2009 at 4:46 am.