Postfix,主机名和/ etc / aliases

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

  1. 我使用亚马逊Linux EC2服务器(一种Centos6)
  2. 我的服务器主机名被设置为srv.example.com
  3. 我已经设置了一个空客户端configuration后缀2.6.6(只为我的网站发送邮件,并发送报告给我的个人邮件)
  4. 我使用包括root: [email protected]在内的规则来设置/etc/aliases root: [email protected]
  5. 我运行newaliases来考虑/etc/aliases的更改
  6. 我重新启动后缀sudo service postfix restart
  7. echo "something" | mailx -s D"subject" root 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 

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

  • 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 

在了解了一个“空客户端”是一个空客户端之后 ,我深入了解了一下如何理解postfix的虚拟域 。

简而言之

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

用正则expression式重写本地邮件

我进一步了解了原始目标用户的信息。 你可以使用正则expression式:

  • /etc/postfix/main.cf ,而不是canonical_maps = hash:/etc/postfix/canonical ,使用canonical_maps = regexp:/etc/postfix/canonical
  • /etc/postfix/canonical ,而不是@srv.example.com [email protected] ,我用(.+)@(.+).example.com [email protected]接收邮件到mymail [email protected](以后我会有srv2,srv3,srvx …)

我太早求助了,希望这个答案能帮助别人坚持同样的问题。