Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i need procmail to place incoming mail into specific folder depending on some set of rules. I know how i can accomplish this, but i need to write static set of rules in a specific file. What i really need is to configure procmail to use rules stored in mysql database. How i can do this? I've read a bit about that and one solution i found is to pipe message to a php/perl script and return a folder name to place message. But i have completely no i idea how to use php script as a rule and then use its return value.

share|improve this question
up vote 0 down vote accepted

To "place incoming mail into [a] specific folder depending on some set of rules" is precisely what Procmail does out of the box, but I guess you are looking for something like this:


It's deceptively simple, but that's really all it takes. A command in backticks will receive the current message as its standard input.

(If $FOLDER is a static file, you need to add locking, but that's a tangential topic.)

If this is all your Procmail rules do, you might want to think about whether Procmail is at all required. The delivery part is still useful and robust, so I recommend you keep it for that, but since Procmail is good at doing precisely what you are trying to do with PHP, perhaps you want to think about your approach.

If your database doesn't change very frequently, you might want to consider using a script to generate your .procmailrc from the database instead. Then the Procmail rules themselves can be static (ideally not require any external process) but you will need to regenerate them whenever the database is updated.

share|improve this answer
Can you tell me, what my script have to return in order to 'do nothing' and continue to the next rules? I want to place rule for my script at first to filter known messages, and all rest check with spamassassin (from the second rule) – WombaT Nov 21 '12 at 8:00
I don't really understand the follow-up question. You mean it should have a way to say "I don't know" and have Procmail fall through? Maybe add a condition to check that the value of FOLDER is not the empty string, * FOLDER ?? . – tripleee Nov 21 '12 at 8:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.