如何更改Postfix中继收件人(smtp_generic_maps不工作)?

我有一个Postfix的邮件网关设置,并希望更改收件人地址。 我希望所有邮件被转发[email protected] ,而不是转发到[email protected]我有postfixconfiguration使用smtp_generic_maps (如下),但是这只适用于邮件正在生成的邮件服务器本身。 任何通过Postfix服务器转发的邮件仍然会去[email protected]有效地忽略smtp_generic_maps 。 我应该考虑什么样的configuration来实现这个目标?

 # grep smtp_generic_maps main.cf smtp_generic_maps = hash:/etc/postfix/generic # postmap /etc/postfix/generic # service postfix reload # cat /etc/postfix/generic [email protected] [email protected] 

你不应该为此使用smtp_generic_maps

后缀地址重写自述文件描述了smtp_generic_maps的正确用法:

使用smtp_generic_maps参数,您可以指定通用(5)查找表,在邮件通过SMTP离开计算机时,通过有效的Internet地址replace本地邮件地址。 通用(5)映射replace信封和标题地址,并且是非recursion的。 当您在本地计算机上的地址之间发送邮件时,不会发生这种情况。

您正尝试使用它(而不是replace本地地址,如[email protected] ),以用FQDN [email protected]replace地址。 由于yahoo.com未在mydestinationconfiguration,因此不会将其视为本地域,因此无法通过通用(5)映射进行处理。

但是,您不应将其他人的域configuration为本地域,因为实际上应该由smtp(8)传递代理来处理。 这样做会阻止任何用户将邮件发送到任何@yahoo.com地址。 这种篡改在技术上是不正确的,甚至可能是非法的。


通过check_recipient_access用户引向公司策略

如果问题在于有人试图通过电子邮件将您的首席执行官发送至个人@yahoo.com地址,并且您想要阻止并强制使用公司电子邮件[email protected] ,则可以将check_recipient_access限制添加到您的main.cf

  smtpd_recipient_restrictions = ... check_recipient_access hash:/etc/postfix/denied_recipients, ... permit 

然后添加一个人类可读理由的拒绝到/etc/postfix/denied_recipients

  [email protected] REJECT The CEO must be contacted using official <[email protected]> address. 

(正如我使用hash:在我的例子中,不要忘记postmap /etc/postfix/denied_recipients 。)


使用transport(5)表来覆盖Postfix的内置默认值

为了使所有[email protected]被传送到[email protected]您可以使用transport_maps而不是smtp_generic_maps

描述

可选传输(5)表指定从电子邮件地址到消息传递传输和下一跳目标的映射。 消息传递传输(如local或smtp)在master.cf文件中定义,下一跳目标通常是主机或域名。 该表是由平凡重写(8)守护进程search的。

这个映射覆盖默认的transport:nexthop内置到Postfix中的transport:nexthopselect。

transport_maps添加到您的/etc/postfix/main.cf

  transport_maps = hash:/etc/postfix/transport 

然后添加到/etc/postfix/transport一行[email protected]更改默认transport:nexthopvirtual:[email protected]

  [email protected] virtual:[email protected] yahoo.com : * : 

其他行只是说,没有对yahoo.com和其他的修改,回落到默认的transport:nexthop行为。