Postfix 中继主机连接失败:接收初始服务器问候语时超时

MrP*_*lTX 6 smtp postfix

我有一个 Elastix 服务器盒,我想从中发送语音邮件的电子邮件通知。我想通过我们公司的电子邮件(由共享网络主机提供商 Bluehost 托管)发送它们。我已按照有关如何使用 Postfix 作为中继服务器的说明进行操作。电子邮件不会发出去。我在日志中得到以下信息(稍微混淆):

Sep 27 16:31:51 TD1000 postfix/smtp[9757]: 1B2C357117: to=<me@mycompany.com>, relay=boxNNN.bluehost.com[a.b.c.d]:465, delay=5241, delays=5076/0.03/165/0, dsn=4.4.2, status=deferred (lost connection with boxNNN.bluehost.com[a.b.c.d] while receiving the initial server greeting)
Run Code Online (Sandbox Code Playgroud)

很多地方都暗示这可能是黑名单问题。但是,对于在我的 PC 上运行的 Outlook 来说,这似乎也是一个问题。我想要做的是让后缀像 Outlook 一样,并使用 SSL 通过 Bluehost 发送。(我的 Outlook 设置:boxNNN.bluehost.com:465,SSL,需要身份验证)

当我进入调试级别时,我收到以下消息:

dns_query: boxNNN.bluehost.com (MX): Host found but no data record of requested type
Run Code Online (Sandbox Code Playgroud)

但是由于最终的消息是没有响应,并且它找到了服务器的 IP 地址,所以我不认为 DNS 问题是问题所在。

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
debug_peer_level = 5
debug_peer_list = boxNNN.bluehost.com
html_directory = no
inet_interfaces = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, localhost.$mydomain, localhost
mydomain = cenginc-office.local
myhostname = td1000.my-office.local
mynetworks = /etc/postfix/network_table
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.5.6/README_FILES
relayhost = boxNNN.bluehost.com:465
sample_directory = /usr/share/doc/postfix-2.5.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtp_connect_timeout = 300
smtp_enforce_tls = yes
smtp_helo_name = my-phone-system
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
smtp_sasl_type = cyrus
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = smtpd
unknown_local_recipient_reject_code = 550
virtual_alias_maps = hash:/etc/postfix/virtual
virtual_mailbox_base = /var/mail/vhosts
virtual_mailbox_domains =
virtual_transport = lmtp:unix:/var/lib/imap/socket/lmtp
Run Code Online (Sandbox Code Playgroud)

(我们根据 Elastix UI 使用 Postifix 2.3.3,所以我不确定为什么样本说 2.5.6)

当我 telnet 到 bluehost 框和端口时,连接会保持打开一小段时间,然后关闭,我想是因为我不是作为 SSL 进入的。

我使用这个网站(以及其他网站)进行配置,但我没有看到我遗漏了什么。https://www.zulius.com/how-to/set-up-postfix-with-a-remote-smtp-relay-host/

关于我做错了什么的任何想法?我的理论是 postfix 没有做 bluehost 在初始连接中期望的东西,但我不知道是什么。谢谢你的帮助。

mas*_*oeh 5

我们有两个事实

  • 您通过端口 465 连接到 bluehost
  • postfix报错误信息:在接收初始服务器问候语时与boxNNN.bluehost.com[abcd]失去连接

一种可能的解释是Postfix 2.11 或更早版本中的 SMTP 客户端不支持 SSL

解释

在 SMTP 中,有两种加密方案:STARTTLS 和 SMTPS。区别在于 (1) SMTPS 要求从第一个字节开始 SSL 加密和 (2) STARTTLS 首先需要纯文本模式,并且可选地客户端和服务器在 STARTTLS 命令之后进行 SSL 协商。

Postfix SMTP 服务器 (smtpd)支持这两种协议。问题是 SMTP 客户端(在 postfix 3.0 之前) -向远程服务器发送电子邮件的客户端- 不支持 SMTPS 连接。它只支持纯文本模式或 STARTTLS 模式。

这里发生的事情是:Postfix SMTP 客户端使用纯文本模式连接到 Bluehost,因为 postfix 要建立 STARTTLS。但是 Bluehost 期望第一个字节是 SSL 协商而不是纯文本。这种不匹配使 Bluehost 服务器静默丢弃数据并断开 postfix。Postfix不知道这里发生了什么,所以它在maillog中抛出错误

Sep 27 16:31:51 TD1000 postfix/smtp[9757]: 1B2C357117: to=<me@mycompany.com>, relay=boxNNN.bluehost.com[a.b.c.d]:465, delay=5241, delays=5076/0.03/165/0, dsn=4.4.2, status=deferred (lost connection with boxNNN.bluehost.com[a.b.c.d] while receiving the initial server greeting)
Run Code Online (Sandbox Code Playgroud)

解决方案

Postfix TLS 文档提供了一种在此处使用 stunnel 的解决方法。所以MrPhilTX 的解决方案对于 Postfix < 3.0 是正确的。

在 postfix 3.0 中,Wietse Venema 决定为 postfix SMTP 客户端提供额外的 SMTPS 功能。有了这个特性,这里就不需要 stunnel 解决方案了。这里有两种变体:

a) 为所有传出 SMTP 连接启用 SMTPS

通常,在这种情况下,postfixrelayhost像 OP 的问题一样只有 SMTPS 。所以

# Client-side SMTPS requires "encrypt" or stronger.
smtp_tls_security_level = encrypt
smtp_tls_wrappermode = yes
# The [] suppress MX lookups.
relayhost = [mail.example.com]:465
Run Code Online (Sandbox Code Playgroud)

b) 启用 SMTPS 到多个主机

对于其他情况,您需要自定义传输和传输映射来选择性地打开 SMTPS

# /etc/postfix/main.cf:
transport_maps = hash:/etc/postfix/transport

# /etc/postfix/transport:
example.com  relay-smtps:example.com:465

#/etc/postfix/master.cf:
relay-smtps  unix  -       -       n       -       -       smtp
    # Client-side SMTPS requires "encrypt" or stronger.
    -o smtp_tls_security_level=encrypt
    -o smtp_tls_wrappermode=yes
Run Code Online (Sandbox Code Playgroud)


MrP*_*lTX 2

我不确定这是否是我应该放置的地方,但这就是我如何让它工作的。

所以,kworr 和 befreeandgood 让我走上了正轨。smtp_sasl_* 不使用 SSL 执行任何操作,仅使用身份验证。

我按照以下链接中的说明进行操作:这个让我关闭了 http://www.eglug.org/book/export/html/1923 ,但遗漏了一些需要设置的内容。添加了这一http://tech.surveypoint.com/blog/relay-mail-with-postfix-and-stunnel/inet_interfaces = loopback_only

这些选项让我遇到了一些问题,邮件服务器拒绝各种标头名称,例如“来自”和“回复”。我通过谷歌搜索找到的一些说明修复了这些问题(但我不允许发布这些链接,因为我已经超出了链接配额)。

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
debug_peer_level = 2
html_directory = no
inet_interfaces = loopback-only
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, localhost.$mydomain, localhost
mydomain = my-office.local
myhostname = td1000.my-office.local
mynetworks = /etc/postfix/network_table
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.5.6/README_FILES
relayhost = 127.0.0.1:5001
sample_directory = /usr/share/doc/postfix-2.5.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtp_connect_timeout = 60
smtp_generic_maps = hash:/etc/postfix/generic
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
smtp_sasl_type = cyrus
smtp_use_tls = yes
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = smtpd
smtpd_tls_auth_only = no
smtpd_tls_loglevel = 2
smtpd_tls_received_header = no
unknown_local_recipient_reject_code = 550
virtual_alias_maps = hash:/etc/postfix/virtual
virtual_mailbox_base = /var/mail/vhosts
virtual_mailbox_domains =
virtual_transport = lmtp:unix:/var/lib/imap/socket/lmtp
Run Code Online (Sandbox Code Playgroud)

因此,smtp_generic_maps 用于将出现的各个地址重命名为实际存在的某个地址。我必须对两个不同的名称执行此操作,这是我通过查看 /var/log/maillog 文件找到的。

因此,连接 Bluehost 的总结如下:

  • 启用 smtp_sasl 身份验证
  • 用于stunnel创建 SSL 隧道
  • 用于smtp_generic_maps映射 asterisk 正在使用的不存在的用户名。
  • 闲逛 mydomain 等可能会让您绕过通用地图要求。我还看到有人提到$myorigin这是一个潜在的解决方法。