使用Postfix将邮件转发到域到不同域的相同地址

有没有一种方法可以configurationPostfix接受域名的任何邮件(全部捕获),然后将该邮件转发到不同域的同一个收件人,而不知道收件人是否真的存在?

我使用Postfix和MySQL支持虚拟帐户。

不,这不是直接可能的。 在http://www.postfix.org/ADDRESS_REWRITING_README.html#luser_relay中介绍的工作方式有一个例外

另一个粗略的解决scheme是使用SQL(substr + concat)来为你在virtual_alias_maps处理这个问题。

编辑 :哦。 还有最后一个可能性。 使用策略委托机制,如果不需要重写,则返回REDIRECT [email protected] ,如果需要的话,返回REDIRECT [email protected]

编辑2 :灵感来自Squidly(但他的解决scheme不起作用!)你可以设置

 virtual_alias_maps = pcre:/etc/postfix/forward_user.pcre, ... 

并在该文件中

 /^(.*)@adomain\.example/ $(1)@other-domain.example 

(注意第一列中的转义点(\))。我个人更喜欢这个版本。

pcre表types在我的系统上不可用,所以我做了以下操作:

  • /etc/postfix/main.cf

     virtual_alias_maps = regexp:/etc/postfix/virtual 
  • /etc/postfix/virtual

     /^([^@]*)@olddomain/ $(1)@newdomain 

如果你使用MySQL作为存储的结束,我相信你可以像这样指定一个catch:

表转发

 | source | destination | |==============|===============| | @example.com | @yoursite.com | 

如果我正确阅读文档,这意味着[email protected]现在将被转发到[email protected]等。

我在这个howtoforge教程中find了这个

不是直接可能的? 我发现它非常简单直接,没有SQL,正则expression式或策略机制。

main.cf

 virtual_alias_domains = alias-destination1.com alias-destination2.com virtual_alias_maps = hash:/etc/postfix/virtual 

/etc/postfix/virtual

 # I want @true-destination.com to have two incoming aliases @alias-destination1.com @true-destination.com @alias-destination2.com @true-destination.com 

从服务器发送testing电子邮件:

 # telnet localhost 25 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 smtp.myserver.com ESMTP Postfix HELO smtp.myserver.com 250 smtp.myserver.com MAIL FROM:<[email protected]> RCPT TO:<[email protected]> 250 2.1.5 Ok DATA 354 End data with <CR><LF>.<CR><LF> Message-ID: <[email protected]> Date: Thu, 05 May 2011 23:59:59 -0400 From: Some Body <[email protected]> To: [email protected] Subject: Hello Just testing. . 

而在mail.log中的实际结果(我有端口10025运行amavis):

 Apr 6 22:39:43 smtp-a postfix/smtpd[4411]: connect from localhost[127.0.0.1] Apr 6 22:39:43 smtp-a postfix/smtpd[4411]: 6B47641AF2: client=localhost[127.0.0.1] Apr 6 22:39:43 smtp-a postfix/cleanup[3706]: 6B47641AF2: message-id=<[email protected]> Apr 6 22:39:43 smtp-a postfix/qmgr[3681]: 6B47641AF2: from=<[email protected]>, size=1115, nrcpt=1 (queue active) Apr 6 22:39:43 smtp-a postfix/smtpd[4411]: disconnect from localhost[127.0.0.1] Apr 6 22:39:43 smtp-a amavis-incoming[2159]: (02159-13) Passed CLEAN {RelayedInternal}, LOCAL [127.0.0.1]:42426 [127.0.0.1] <[email protected]> -> <[email protected]>, Queue-ID: 5C61F41AE5, Message-ID: <[email protected]>, mail_id: hUbzH1PtXlzl, Hits: 2.605, size: 394, queued_as: 6B47641AF2, 1224 ms Apr 6 22:39:43 smtp-a postfix/lmtp[3687]: 5C61F41AE5: to=<[email protected]>, relay=127.0.0.1[127.0.0.1]:10024, delay=25, delays=24/0/0/1.2, dsn=2.0.0, status=sent (250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 6B47641AF2) Apr 6 22:39:43 smtp-a postfix/qmgr[3681]: 5C61F41AE5: removed 

重点线分开重点:

 Apr 6 22:39:43 smtp-a postfix/smtp[3684]: 6B47641AF2: to=<[email protected]>, orig_to=<[email protected]>, relay=10.0.0.245[10.0.0.245]:2525, delay=0.03, delays=0.01/0/0/0.02, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 705AA40459) Apr 6 22:39:43 smtp-a postfix/qmgr[3681]: 6B47641AF2: removed 

根据你如何设置你的Postfix,你可以使用别名来转发所有的邮件。

编辑

你也可以设置一个redirect,为你轻松做到这一点。

在/etc/postfix/main.cf添加这个:

 recipient_bcc_maps = pcre:/etc/postfix/forward_bcc.pcre 

然后在/etc/postfix/forward_bcc.pcre中添加这个:

 /^[email protected]/ [email protected] 

这是一个黑客,但它将适用于转发特定用户从一个域到另一个。

你也可以看看这个页面,了解如何在Postfix中进行一些重写。