Have you tried MySQLTuner yet? It's free and it makes optimizing your MySQL server easier than ever!

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.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis
5 Responses to “Sort e-mail in Plesk with procmail”
  1. 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.

  2. 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.

  3. @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.

  4. 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.

  5. @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.

Leave a Reply

You must be logged in to post a comment. Login »