大网数据广告活动
服务器运维问答

postfix smtp_generic_maps with regular expression

· 52CE 我爱测

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 …

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-09-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。