问题原文
原帖链接 · Chebarbudo · CC BY-SA 4.0
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 omitted] [email omitted]
[email omitted] [email omitted]
And so far it works. When user santiago sends an email, it is sent as [email omitted] 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.$[email omitted]
Is it at all possible?
Thanks for your help
Santiago
已采纳解答
原帖链接 · anx · CC BY-SA 4.0
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.$[email omitted]
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
