Postfix: triggering perl script on receipt of each email

So, I have a nice Postfix system up and running, using the Linode HOWTO in the library. Virtual users, with MySQL authentication, etc. I would like Postfix to trigger a perl script on the receipt of every email, with the raw email data as a parameter. Is this possible? If so, how?

I've done a similar thing by periodically scanning mailboxes, but I would like it to be more immediately reactive.

Thanks in advance.

EDIT: I guess I could piggyback off the Spam Assassin process, which is run for each email. Is there a better way?

3 Replies

There are a few options for integrating filters into Postfix, but they can be… complex.

A simpler method might be to watch the directory containing mailboxes with something like inotifywait (looks like similar modules are available for Perl).

Thanks for the info.

All these options could cause bad things to happen to my mail if my script doesn't behave properly. This is a possibiilty due to my limited perl skills. And, you're right, filtering is complex if we don't use the simple (and dangerous) example that Postfix provides.

The ionotify options with perl appears to require a persistent process to wait for the trigger, which I would prefer not to have.

I think I will stick with periodically scanning mailboxes. Thanks for your reply, though.

Periodic might be better. If you receive a sudden deluge of mail and your Perl is expensive, it might result in a denial of service.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct