指定 Postfix 实例来发送出站电子邮件

指定 Postfix 实例来发送出站电子邮件

我有一台 CentOS 6.5 服务器,运行 Postfix 2.6x(默认发行版),绑定了五个公共 IPv4 IP。每个 IP 都单独设置了 DNS 和 rDNS。每个 IP 在不同的域中使用不同的主机名。我有五个 Postfix 实例,每个 IP 绑定一个,如下例所示:

  • 192.168.34.104 red.example.com /etc/postfix
  • 192.168.36.48 green.example.net /etc/postfix-green
  • 192.168.36.49 pink.example.org /etc/postfix-pink
  • 192.168.36.50 orange.example.info /etc/postfix-orange
  • 192.168.36.51 blue.example.us /etc/postfix-blue

我通过 telnet 到端口 25 测试了每个 IP。Postfix 正确响应并使用正确的主机名显示横幅。所有这些实例都毫无问题地接收了电子邮件,并路由到正确的位置。除了最后一个实例外,此设置已存在几年并且有效。

但是,我从未费心设置通过主实例以外的任何实例发送的出站电子邮件;没有必要。现在我需要从 blue.example.us 发送电子邮件,这些电子邮件实际上从该接口和 IP 发出,这样 Received 标头就会显示 blue.example.us 为发送邮件主机,以便 SPF 和 DKIM 进行验证,等等。

将从 blue.example.com 发送的电子邮件是由服务器上的单个 shell 帐户 (account5) 发送的反馈循环,该帐户专门用于发送此电子邮件。该帐户从其他网络上的服务器接收反馈循环电子邮件,保存这些电子邮件的正文,然后生成新的出站电子邮件标头,附加保存的正文,并发送电子邮件。它通过将每封电子邮件传输到 来发送sendmail -oi -t。我们这样做是为了掩盖初始服务器的身份。处理这些电子邮件的 procmail 脚本正常工作。

但是,我不能配置此帐户以通过正确的 Postfix 实例/IP/接口发送电子邮件。完全相同的帐户和脚本通过主 Postfix 实例 /etc/postfix 发送电子邮件,没有任何问题。但是,当我在 .bash_profile 或处理此电子邮件的 Procmail 脚本中将 MAIL_CONFIG 更改为指向 /etc/postfix-blue 时,我收到此错误:

sendmail: fatal: User account5(###) is not allowed to submit mail

我已经阅读了 Postfix.org 上的手册,在 Google 上搜索过,并尝试了 ServerFault.com 上之前三个答案中的建议:

Postfix - 指定传递出站邮件的接口

Postfix 用户无权提交邮件

Postfix 拒绝 php 邮件

每次更改配置后,我都会小心地停止并重新启动 Postfix,并测试结果。但什么都没起作用。主 postfix 实例很乐意接受来自 account5 的出站电子邮件。postfix-blue 实例继续拒绝来自 account5 的电子邮件,并出现上述 sendmail 错误。

尽管我很容易将责任归咎于机器敌意,但我知道我肯定是忽略了什么或做错了什么。有人能告诉我可能是什么吗?如果您需要有关我的设置的更多信息,请随时询问。

=-=-=-=-=-=-=-=-=-=

应响应者的请求,以下是 a) 主后缀实例 (“red.example.com”) 和 b) FBL 实例 (“blue.example.us”) 的 main.cf 和 master.cf

[注意:下面未指定的所有参数均保留为 Postfix 2.6 的默认设置]

主要的:

主配置文件

smtp      inet  n       -       n       -       -       smtpd

主配置文件

myhostname = red.example.com
mydomain = example.com
inet_interfaces = $myhostname, localhost
inet_protocols = all
lmtp_host_lookup = native
smtp_host_lookup = native
ignore_mx_lookup_error = yes
mydestination = $myhostname, localhost.$mydomain, localhost
local_recipient_maps =
mynetworks = 192.168.34.104/32
relay_domains = example.com,
            example.info,
            example.net,
            example.org,
            example.us
relayhost = [192.168.34.102] # Separate physical server, main mailserver.
relay_recipient_maps = hash:/etc/postfix/relay_recipients
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
smtpd_banner = $myhostname ESMTP $mail_name
multi_instance_wrapper = ${command_directory}/postmulti -p --
multi_instance_enable = yes
multi_instance_directories = /etc/postfix-green /etc/postfix-pink /etc/postfix-orange /etc/postfix-blue

自由基清单:

主配置文件

184.173.119.103:25      inet  n       -       n       -       -       smtpd

主配置文件

myhostname = blue.example.us
mydomain = blue.example.us <= Deliberately set to subdomain only.
myorigin = $mydomain
inet_interfaces = $myhostname
lmtp_host_lookup = native
smtp_host_lookup = native
ignore_mx_lookup_error = yes
mydestination = $myhostname
local_recipient_maps  = unix:passwd.byname $alias_maps $virtual_alias_maps
mynetworks = 192.168.36.51/32, 192.168.35.20/31 <= Second IP is backup MX servers
relay_domains = $mydestination
recipient_canonical_maps = hash:/etc/postfix-blue/canonical
virtual_alias_maps = hash:/etc/postfix-fbl/virtual
alias_maps = hash:/etc/aliases, hash:/etc/postfix-blue/canonical
alias_maps = hash:/etc/aliases, hash:/etc/postfix-blue/canonical
mailbox_command = /usr/bin/procmail -a "$EXTENSION" DEFAULT=$HOME/Mail/ MAILDIR=$HOME/Mail
smtpd_banner = $myhostname ESMTP $mail_name
authorized_submit_users = 
multi_instance_name = postfix-blue
multi_instance_enable = yes

** 测试 Masegaloeh 的最新建议后获得的附加信息 **

我刚刚尝试将“account5”添加到 authorized_submit_users,并在 .bash_profile 中为“account5”shell 帐户设置 MAIL_CONFIG,同时设置“export MAIL_CONFIG”。Procmail 不再抱怨;它认为它正在正确生成和发送 FBL。但是,maillog 报告以下内容:

May 29 14:47:42 newton postfix-blue/qmgr[3522]: 5BC773E612F: from=<[email protected]>, size=1106, nrcpt=1 (queue active)
May 29 14:47:42 newton postfix-blue/qmgr[3522]: warning: connect to transport private/smtp: Connection refused
May 29 14:47:42 newton postfix-blue/error[3766]: 5BC773E612F: to=<[email protected]>, relay=none, delay=0.01, delays=0/0/0/0, dsn=4.3.0, status=deferred (mail transport unavailable)

也许我需要在传输配置文件中添加一些内容吗?

答案1

当您通过本地提交发送电子邮件时sendmail它将使用默认实例,例如red.example.com。此行为已在postfix 官方文档

一个 Postfix 实例比较特殊:该实例的配置目录是编译到 Postfix 实用程序中的默认配置目录。默认配置目录的位置通常为 /etc/postfix,可通过“postconf -d config_directory”命令查询。我们将具有此配置目录的实例称为“默认实例”。

默认实例负责本地邮件提交。setgid postdrop(1) 实用程序由 sendmail(1) 本地提交程序使用,将消息放入默认实例队列目录的 maildrop 子目录中。

即使在极少数情况下使用“sendmail -C”将本地邮件提交到非默认的 Postfix 实例,出于安全原因,postdrop(1) 也会查阅默认的 main.cf 文件来检查所请求的非默认配置目录的有效性。

因此,虽然在大多数其他方面,所有实例都是平等的,但默认实例“比其他实例更平等”。您可以选择创建其他实例,但必须至少拥有默认实例,其配置目录位于默认的编译位置。

一些建议:

  1. 根据以上代码片段,您可以尝试使用sendmail -C来指定提交电子邮件的实例。或者
  2. 另一种解决方法是交换实例,例如red.example.com变得 蓝色.example.us反之亦然。

根据以下评论进行编辑

sendmail: fatal: User account5(###) is not allowed to submit mail

上述错误authorized_submit_users是由参数为空(postfix-blue 实例)引起的。结果是没有人可以sendmail通过 postfix-blue 实例执行。添加account5该参数应该可以解决问题。

另一个错误

warning: connect to transport private/smtp: Connection refused

因缺失而导致smtp 传输主配置文件. 确保 master.cf 中有此行

smtp      unix  -       -       n       -       -       smtp

并添加-o smtp_bind_address=192.168.36.51在行尾,因此电子邮件将通过地址 192.168.36.51 发送。

相关内容