1

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:

santiago@uranus.caoba.fr        santiago.uranus.caoba.fr@caoba-mail.fr
auguste@uranus.caoba.fr         auguste.uranus.caoba.fr@caoba-mail.fr

And so far it works. When user santiago sends an email, it is sent as santiago.uranus.caoba.fr@caoba-mail.fr 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  $1.$hostname@caoba-mail.fr

Is it at all possible?

Thanks for your help

Santiago

Chebarbudo
  • 73
  • 1
  • 6

1 Answers1

5

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/  $1.$2.caoba.fr@caoba-mail.fr

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.

anx
  • 6,875
  • 4
  • 22
  • 45