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