使用Postfix转发邮件时,如何保存本地邮件副本?

这个问题有一个相关的答案在这里: 如何转发邮件,同时使用后缀和MySQL保存副本? 但是有两个问题:

  1. OP的设置使用了MySQL,所有的答案都是针对这个的
  2. 似乎是我想要的答案,使用main.cf和哈希表的答案是从2009年开始的(并且没有被重视)。 所以我想再次问一下这个configuration文件的设置,而不是MySQL的设置。

我正在使用/etc/postfix/main.cf中的这些行成功地将邮件转发到我的Gmail地址:

virtual_alias_domains = example.com, example.net virtual_alias_maps = hash:/etc/postfix/virtual 

并在/ etc / postfix / virtual中:

 @example.com myusername @example.net myusername myusername [email protected] 

这工作很好,并转发所有邮件[email protected],但我想保留在服务器上的副本。 理想情况下,他们会去myusername的收件箱。 什么是正确的方法来做到这一点?


发送testing邮件后,我的/var/log/mail.log日志:

 Oct 8 09:16:26 myservername postfix/qmgr[1494]: 89736105BA7: from=<[email protected]>, size=1676, nrcpt=2 (queue active) Oct 8 09:16:26 myservername postfix/trivial-rewrite[7338]: warning: do not list domain mydomain.com in BOTH mydestination and virtual_alias_domains Oct 8 09:16:26 myservername postfix/cleanup[7339]: B7888105BB0: message-id=<CAGS0grDYkvWj_wxpGKW1h7XJZ5YEky3DwPBnB4XdvE3TU-W7jg@mail.gmail.com> Oct 8 09:16:26 myservername postfix/local[7340]: 89736105BA7: to=<[email protected]>, relay=local, delay=0.21, delays=0.19/0.01/0/0.01, dsn=2.0.0, status=sent (forwarded as B7888105BB0) Oct 8 09:16:26 myservername postfix/qmgr[1494]: B7888105BB0: from=<[email protected]>, size=1802, nrcpt=1 (queue active) Oct 8 09:16:26 myservername postfix/smtpd[7335]: disconnect from mail-io0-f171.google.com[209.85.223.171] Oct 8 09:16:27 myservername postfix/smtp[7341]: connect to gmail-smtp-in.l.google.com[2607:f8b0:400e:c04::1a]:25: Network is unreachable Oct 8 09:16:27 myservername postfix/smtp[7342]: connect to gmail-smtp-in.l.google.com[2607:f8b0:400e:c04::1a]:25: Network is unreachable Oct 8 09:16:27 myservername postfix/smtp[7342]: B7888105BB0: to=<[email protected]>, orig_to=<[email protected]>, relay=gmail-smtp-in.l.google.com[74.125.28.26]:25, delay=0.89, delays=0/0.01/0.6/0.27, dsn=2.0.0, status=sent (250 2.0.0 OK 1444310187 n40si31732683ioi.161 - gsmtp) Oct 8 09:16:27 myservername postfix/qmgr[1494]: B7888105BB0: removed 

只要修改最后一行

 myusername [email protected] 

所以它成为

 myusername myusername [email protected] 

说明

当postfix发现一个地址是 别人 自己的时候 , 邮件会被传递给相应的用户