I just started playing around with sender address rewriting with postfix. I run a server with debian-7.11 and postfix-2.9.6.

Content of /etc/postfix/main.cf:

smtp_generic_maps = hash:/etc/postfix/generic

Content of /etc/postfix/generic:

[email protected]        [email protected]
[email protected]         [email protected]

And so far it works. When user santiago sends an email, it is sent as [email protected] which is what I want.

My problem is that I want this rewrite to be performed with any user without having to add more lines to /etc/postfix/generic. So I was wondering if it could be done via some kind of regular expression like:

(.*)@$hostname  [email protected]

Is it at all possible?

Thanks for your help



1 Answer 1


The postfix manual explicitly notes when interpolation in regexp or pcre tables is forbidden (mostly due to the authors belief that its use is insecure in that context). If the relevant mapping does not say that it is not, interpolation is available by default.

You can do more complex mappings with the SQL lookups, but as long as your host names are fixed and only subdomains of domains you own, regex will entirely suffice.

Install a suitable regexp module for postfix

apt install postfix-pcre

Add the new /etc/postfix/generic.pcre table:

/([a-z]+)@([^.]+)\.caoba\.fr/  [email protected]

Change the table type (that is replacing your existing hash-type mapping!):

postconf -e smtp_generic_maps=pcre:/etc/postfix/generic.pcre

You probably still want to check if you have append_dot_mydomain enabled (afaik that used to be enabled by default). Debian installs all the relevant manuals, so man 5 generic will bring up the explanation.

You must log in to answer this question.

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