Postfix、主机名和 /etc/aliases

Postfix、主机名和 /etc/aliases

在 SF/SO 上挖掘了几个小时并在 Google 上搜索了很多次之后,我仍然无法弄清楚 postfix 如何使用 /etc/aliases。

  1. 我使用 Amazon Linux EC2 服务器(类似 Centos6)
  2. 我的服务器主机名设置为srv.example.com
  3. 我已经安装了 postfix 2.6.6空客户端配置(仅向我的网站发送邮件和向我的个人邮箱发送报告)
  4. 我制定了/etc/aliases规则,包括root: [email protected]
  5. 我跑步newaliases是为了考虑到/etc/aliases
  6. 我重新启动了 postfixsudo service postfix restart
  7. echo "something" | mailx -s D"subject" root发送邮件[email protected][email protected]

我追踪了这一点/var/log/maillog

Mar 13 17:21:23 srv postfix/smtpd[14462]: A27B540A87: client=localhost[127.0.0.1]
Mar 13 17:21:23 srv postfix/cleanup[14466]: A27B540A87: message-id=<55031c93.Il7wUJmrkLu/WLNL%[email protected]>
Mar 13 17:21:23 srv opendkim[2065]: A27B540A87: DKIM-Signature field added (s=prod-key-swf, d=example.com)
Mar 13 17:21:23 srv postfix/qmgr[14458]: A27B540A87: from=<[email protected]>, size=820, nrcpt=1 (queue active)
Mar 13 17:21:23 srv sendmail[14461]: t2DHLNlC014461: to=root, [email protected] (serveur srv) (500/500), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30309, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (Ok: queued as A27B540A87)
Mar 13 17:21:25 srv postfix/smtp[14467]: A27B540A87: to=<[email protected]>, relay=aspmx.l.google.com[64.233.186.27]:25, delay=2, delays=0.1/0.01/1.4/0.48, dsn=5.1.1, status=bounced (host aspmx.l.google.com[64.233.186.27] said: 550-5.1.1 The email account that you tried to reach does not exist. Please try 550-5.1.1 double-checking the recipient's email address for typos or 550-5.1.1 unnecessary spaces. Learn more at 550 5.1.1 http://support.google.com/mail/bin/answer.py?answer=6596 f78si2479139qkh.47 - gsmtp (in reply to RCPT TO command))
Mar 13 17:21:26 srv postfix/bounce[14468]: A27B540A87: sender non-delivery notification: 2297E40A86
Mar 13 17:21:26 srv postfix/qmgr[14458]: A27B540A87: removed

我唯一的后缀配置修改是(空客户端配置):

  • myhostname = srv.example.com
  • myorigin = $mydomain
  • relayhost = $mydomain
  • inet_interfaces = loopback-only
  • mydestination =

为了按预期应用 /etc/aliases 语句,我缺少哪个步骤?

我的sudo postconf -n

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
html_directory = no
inet_interfaces = loopback-only
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
milter_default_action = accept
mydestination =
myhostname = srv.example.com
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
non_smtpd_milters = $smtpd_milters
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
relayhost = $mydomain
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_milters = inet:127.0.0.1:8891
unknown_local_recipient_reject_code = 550

答案1

在理解了“空客户端”是空客户端,我进一步了解postfix 虚拟域怎么用

简而言之

  1. 空客户端是“仅发送”邮件服务器的理想选择(我的网站需要的服务器)
  2. 配置“空客户端”需要定义myorigin服务器主机名
  3. myorigin also specifies the default domain name that is appended to recipient addresses that have no @domain part(取自/et/postfix/main.cf)。
  4. Postfix 不会使用我的/etc/aliases来路由我的本地邮件,因为发送到root/ fail2ban/ me... 的邮件将被重写为[email protected]/ [email protected]...
  5. 然后我需要 postfix 来重写[email protected][email protected]
  6. 加入​@srv.example.com [email protected]/etc/postfix/canonical
  7. 加入canonical_maps = hash:/etc/postfix/canonical/etc/postfix/main.cf
  8. 运行postmap /etc/postfix/canonical并重新启动 postfix ( sudo service postfix restart)

使用正则表达式重写本地邮件

我做了一些进一步的工作来保留原始目标用户的信息。您可以使用正则表达式来实现这一点:

  • 代替/etc/postfix/main.cfcanonical_maps = hash:/etc/postfix/canonical使用canonical_maps = regexp:/etc/postfix/canonical
  • /etc/postfix/canonical,而不是,我过去常常收到邮件到@srv.example.com [email protected](.+)@(.+).example.com [email protected][电子邮件保护](稍后我会有 srv2、srv3、srvx……)

我太早寻求帮助了,希望这个答案能够帮助其他遇到同样问题的人。

相关内容