How can I route some emails to a script in Postfix?

Okay. And now a different approach.

Put a new transport in master.cf:

coolscript unix -    n    n    -    50    pipe
    flags=R user=vmail argv=/path/to/script -o SENDER=${sender} -m USER=${user} EXTENSION=${extension}

you can extend/modify the parameters as you like.

Then (to eliminate pcre) you can use regexp to do the "catch-thing" in main.cf:

transport_maps = regexp:/etc/postfix/redirect.regexp

And in /etc/postfix/redirect.regexp you put:

/^user-.*@example\.com/   coolscript:

Reload Postfix with postfix reload.


First check if you have pcre compiled into Posfix with postconf -m. Then you can set in main.cf:

virtual_alias_maps = pcre:/etc/postfix/redirect.pcre

and in /etc/postfix/redirect.pcre you put:

/^user-.*@example\.com$/   somelocalalias

and in /etc/aliases you add

somelocalalias: |"/path/to/script"

Don't forget to postalias /etc/aliases and afterwards reload Postfix with postfix reload.