10

How do I route all emails directed to user-*@example.com (i.e. [email protected]) to a pipe command in Postfix? The idea is to create craigslist-style anonymization by assigning dynamic email aliases to each user. I can't seem to find relevant information in the documentation, however.

2 Answers 2

12

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.

3
  • if I put /example.com/ it'll work and my data gets recorded, if I put /^user-.*@example.com/ it'll get a relay access denied, any idea why? I already have relay_domains=$mydestination, $transport_maps but apparently that doesnt solve the problem May 22, 2014 at 12:56
  • 2
    @ChristopherThomas You did not escape the dot in example.com?!
    – mailq
    Jan 12, 2022 at 22:32
  • oops, good catch, thanks! Jan 13, 2022 at 8:50
5

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.

4
  • Is there a reason you're suggesting pcre over regexp? Also, shouldn't I be specifying the pipe in master.cf? Oct 18, 2011 at 19:15
  • 1
    @If you know the answer why ask? Sure there are more ways to achieve the same. If you prefer regexp then go for it. Even transports in master.cf can do it if you watch out for chroot pitfalls.
    – mailq
    Oct 18, 2011 at 19:23
  • This was the magic I needed to make my script work. Transport wasn't working for some reason, this worked first time.
    – n0nag0n
    Oct 26, 2015 at 23:36
  • Under which user is the script from /etc/aliases run?
    – Marki555
    Aug 25, 2017 at 11:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .