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

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

这个问题在这里有一个相关的答案:如何使用 postfix 和 mysql 转发邮件并保存副本?但它存在两个问题:

  1. OP 的设置使用 MySQL,并且所有答案都针对它,并且
  2. 我想要的答案似乎是使用 main.cf 和哈希表的答案,它来自 2009 年(当时没有引起注意)。所以我想再次询问这个问题,关于配置文件设置而不是 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]

这很有效,并将所有邮件转发至[电子邮件保护],但我想在服务器上保留一份副本。理想情况下,它们会进入我的用户名的收件箱。正确的做法是什么?


发送测试电子邮件后,我的 /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

答案1

只需修改最后一行

myusername [email protected]

所以它变成

myusername myusername [email protected]

解释

当 postfix 发现一个地址被别名为他自己, 然后邮件将发送给相应的用户

答案2

您还可以在用户的​​主目录中设置一个文件 .forward,其内容如下:

\myusername, [email protected]

更多详情可在这找到:https://www.ccsf.edu/Pub/UNIXhelp/mail/file_forward.htmlhttp://www.postfix.org/local.8.html

系统管理员可以设置一个或多个系统范围的 send-mail 样式别名数据库。用户可以拥有 sendmail 样式 ~/.forward 文件。name 的邮件将投递到别名 name、~name/.forward 中的目的地、用户名拥有的邮箱,或者作为无法投递的邮件被退回。

   The system administrator can specify a comma/space  separated  list  of
   ~/.forward like files through the forward_path configuration parameter.
   Upon delivery, the local delivery agent tries each pathname in the list
   until a file is found.

   Delivery via ~/.forward files is done with the privileges of the recip-
   ient.  Thus, ~/.forward like files must be readable by  the  recipient,
   and  their  parent directory needs to have "execute" permission for the
   recipient.

   The forward_path parameter is subject to interpolation of $user (recip-
   ient  username),  $home  (recipient  home directory), $shell (recipient
   shell), $recipient (complete recipient address), $extension  (recipient
   address  extension), $domain (recipient domain), $local (entire recipi-
   ent   address   localpart)   and   $recipient_delimiter.   The    forms
   ${name?value}  and  ${name:value}  expand  conditionally  to value when
   $name is (is not) defined.  Characters that may have special meaning to
   the  shell  or  file  system  are replaced by underscores.  The list of
   acceptable characters is specified  with  the  forward_expansion_filter
   configuration parameter.

   An  alias  or ~/.forward file may list any combination of external com-
   mands, destination file names, :include: directives, or mail addresses.
   See  aliases(5)  for a precise description. Each line in a user's .for-
   ward file has the same syntax as the right-hand part of an alias.

   When an address is found in its own alias expansion, delivery  is  made
   to the user instead. When a user is listed in the user's own ~/.forward
   file, delivery is made to the user's mailbox instead.  An empty ~/.for-
   ward file means do not forward mail.

   In  order to prevent the mail system from using up unreasonable amounts
   of memory, input records read from :include: or from  ~/.forward  files
   are broken up into chunks of length line_length_limit.

   While  expanding  aliases,  ~/.forward  files,  and  so on, the program
   attempts to avoid duplicate deliveries. The duplicate_filter_limit con-
   figuration parameter limits the number of remembered recipients.

相关内容