厨师服务器不发送邮件

chef server doesn't send mails

我在 CentOS 6.6 上安装了 Chef-server 12。当我想在页面 https://ip/password-reset/new 上提醒我用户密码时,我没有收到任何邮件 在 exim 日志中我看到

2016-04-27 14:52:17 1avQp7-0001iP-0U <= <> R=1avQp6-0001iO-Om U=exim P=local S=1611
2016-04-27 14:52:17 1avQp7-0001iP-0U => opscode <opscode@non_resorvable_fqdn> R=localuser T=local_delivery
2016-04-27 14:52:17 1avQp7-0001iP-0U Completed
2016-04-27 14:53:23 Start queue run: pid=6616
2016-04-27 14:53:23 End queue run: pid=6616

但是当我用 xmail 发送邮件时一切正常

2016-04-27 14:45:05 1avQi9-0001g2-DL <= user@non_resorvable_fqdn U=ec2-user P=local S=611
2016-04-27 14:45:05 1avQi9-0001g2-DL gmail-smtp-in.l.google.com [2a00:1450:4013:c00::1a] Network is unreachable
2016-04-27 14:45:08 1avQi9-0001g2-DL => user2@gmail.com R=dnslookup T=remote_smtp H=gmail-smtp-in.l.google.com [173.194.65.27] X=UNKNOWN:ECDHE-RSA-AES128-GCM-SHA256:128
2016-04-27 14:45:08 1avQi9-0001g2-DL Completed
2016-04-27 14:49:44 1avQme-0001hE-4B <= <> R=1avQme-0001hD-2t U=exim P=local S=1611
2016-04-27 14:49:44 1avQme-0001hE-4B => opscode <opscode@non_resorvable_fqdn> R=localuser T=local_delivery
2016-04-27 14:49:44 1avQme-0001hE-4B Completed

我收到了这封邮件

检查您的 Chef 日志和 MTA(exim、postfix 等)日志和配置。在我的例子中,在安装 chef-manage 之后,在 Web UI 上点击日志中的 "reset password" /var/log/chef-manage/web/current 我发现:

[date] INFO -- :   Rendered password_reset_mailer/password_reset.text.erb (1.2ms)
[date] sh: 1: /usr/sbin/sendmail: not found

我安装了 postfix,现在可以正常发送邮件了。 所以我认为在你的情况下 exim 是个问题。

Chef 在发送邮件时使用 sendmail -t 参数。此选项在 sendmail 的各种实现中有不同的解释。

来自 exim 手册页:

-t

When Exim is receiving a locally-generated, non-SMTP message on its standard input, the -t option causes the recipients of the message to be obtained from the To:, Cc:, and Bcc: header lines in the message instead of from the command arguments. The addresses are extracted before any rewriting takes place and the Bcc: header line, if present, is then removed.

If the command has any arguments, they specify addresses to which the message is not to be delivered. That is, the argument addresses are removed from the recipients list obtained from the headers. This is compatible with Smail 3 and in accordance with the documented behaviour of several versions of Sendmail, as described in man pages on a number of operating systems (e.g. Solaris 8, IRIX 6.5, HP-UX 11). However, some versions of Sendmail add argument addresses to those obtained from the headers, and the O'Reilly Sendmail book documents it that way. Exim can be made to add argument addresses instead of subtracting them by setting the option extract_addresses_remove_arguments false.

因此,要使 exim 与 Chef 服务器一起工作,您需要添加:

extract_addresses_remove_arguments = false

到您的 exim 配置的 main/02_exim4-config_options 部分

如果您选择了使用单个配置文件的选项,则您的配置位于:

/etc/exim4/exim4.conf.template(在 debian 系统上)

然后重启 exim 就可以了。

另请参阅:https://github.com/mikel/mail/issues/70