Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 have a centOS server with qmail and I want to set it up so that every time an email is delivered, a php script is run immediately after. I don't need to "forward" the specific message to the php script, just to trigger its execution whenever qmail delivers a message. However, if I could let the script know at least which mailbox received the message, that would be great (I would avoid uselessly checking ALL mailboxes which is what my script currently does)

At the moment I'm accomplishing this by running my php script via a cronjob every minute, but I would like to avoid uselessly running the script when no mail is being received, and to avoid the half-a-minut-average delay.

How do I set up qmail to trigger the execution of a program after delivering a message?

share|improve this question
@mailq make that an answer and earn some free rep. – voretaq7 Oct 6 '11 at 20:31
up vote 2 down vote accepted

The easiest way by far will be using the dot-qmail configuration files for every mailbox you want to to invoke your script for. You can read about dot-qmail here and the enviromental parameters you can use in qmail-command

share|improve this answer
Is it possible to put the .qmail file in a place where it will apply to all incoming mail instead of only that addressed to a particular mailbox? I have dozens of mailboxes! – matteo Nov 28 '11 at 19:42
You can use .qmail-default which should be found in the root directory of your domain and it applies for the whole domain – thanosk Nov 29 '11 at 7:47

So the answer is procmail. As I'm not a qmail guy I can't tell you how you integrate it into qmail. But probably the answer is here.

Then you need a recipe to trigger the program and after that deliver the mail as before. The complete documentation is also online available:

Procmail is ancient (but robust!) software. We still use it to do Spam filtering (yes, indeed) for about 500,000 mails daily.

share|improve this answer

If you're using dovecot, you can also add managesieve to dovecot, and have it do stuff for you when certain mail comes in. I'm a big fan of the procmail method too. Sieve also lets you do other really cool things, and it's not as "ancient" as procmail.

share|improve this answer

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.