无法建立远程 imap 连接,为什么?

无法建立远程 imap 连接,为什么?

远程 CentOS 7 Web 服务器能够成功接收从互联网上其他地方发送的电子邮件,地址为[电子邮件受保护]。在同一 CentOS 7 服务器上运行的应用程序能够使用 JavaMail 与存储传入消息的 dovecot Maildir 建立 IMAP 连接。 那么,为了让我的 devbox 上运行的 Thunderbird 能够通过互联网与远程 CentOS 7 服务器建立 IMAP 连接,我需要添加什么呢?

到目前为止,我已经添加到了imapsfirewalld的公共区域。我还确认 dovecot.conf 包含该行protocols = imap pop3。我将 Thunderbird 配置为使用 IMAP 接收邮件,以 mydomain.com 作为主机名,使用端口 993 和 SSL,使用普通密码。我在域名注册商的网站上确认 dns mx 条目使用 mydomain.com 作为 mx 地址。

编辑

为了回答@Celada的问题,我发布了Thunderbird给出的对话框,表明它在尝试确认我的登录信息时无法连接到服务器。当我为 imap 指定端口 993、为 smtp 指定端口 25 以及指示 SSL 连接时,我会得到相同的信息。此外,将 .mydomain.com 更改为 mydomain.com 并不能消除登录失败的问题。

接下来我将尝试访问防火墙日志并发布结果。我的理解是firewalld不会自动登录,所以我必须开发一些丰富的规则。确定正确的语法可能需要一些时间。

我认为这是服务器配置问题。我犹豫是否要显示 Thunderbird 对话框,因为我不想给人留下这是客户端问题的印象。我认为在设置 Thunderbird 之前需要确定/设置服务器配置。

编辑#2

根据@Celada的建议,我输入telnet localhost 143并得到以下回复:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE STARTTLS LOGINDISABLED] Dovecot ready.  

我也输入了内容telnet localhost 25,然后得到了以下回复:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mydomain.com ESMTP Postfix

这些 telnet 结果指出,firewalld 将 imaps 和 smtp 映射到了错误的端口,因此我键入nano /usr/lib/firewalld/services/imaps.xml并将端口从 993 更改为 143。然后我键入nano /usr/lib/firewalld/services/smtp.xml并将端口更改为 25。

然后我输入firewall-cmd --reload以确保更改生效。

接下来,我将新信息放入 Thunderbird 并再次尝试测试连接,但再次收到以下对话框所示的失败消息:

请注意,我在域名注册商处检查了 DNS 中的 MX 记录,它是准确的mydomain.com,如屏幕截图所示。我不明白这有什么无关紧要的。我确实检查过,服务器上的主机名也是mydomain.com.我是否应该检查其他资源以确认正确的邮件服务器名称?

另请注意,dovecot 和 postfix 是使用标准配置安装的。我没有明确配置 ssl 来与它们一起工作,尽管 SSL 可能是默认配置的一部分。但是,我确实更改了上面对话框中的设置并测试了与没有任何在 SSL 字段中指定,但收到相同的失败消息。

在上面最新(底部)屏幕截图之后,/var/log/maillog 中的 dovecot 日志是:

Feb 27 00:52:57 mydomain dovecot: imap-login: Aborted login (no auth attempts in 0 secs): user=<>, rip=my.DEVBOX.ip.addr, lip=my.SERVER.ip.addr, session=<YsH2egsQAABi9AyF>

编辑#3

按照 @Bandrami 的建议,我将protocols = imap pop3dovecot.conf 更改为protocols = imaps pops.然后我确保/usr/lib/firewalld/services/imaps.xml指定端口 993。我键入firewall-cmd --reloadsystemctl stop dovecot然后systemctl start dovecot重新启动服务器上的相关进程。然后,我将 Thunderbird 测试配置为指定端口 993 和 SSL/TLS,并在 Thunderbird 中重新运行连接测试,结果在 Thunderbird 中得到相同的结果。

然而,dovecot 日志更加明确,如下所示:

Feb 27 01:18:20 mydomain dovecot: config: Warning: NOTE: You can get a new clean config file with: doveconf -n > dovecot-new.conf
Feb 27 01:18:20 mydomain dovecot: config: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:26: 'imaps' protocol can no longer be specified (use protocols=imap). to disable n$
Feb 27 01:18:38 mydomain dovecot: imap-login: Disconnected (no auth attempts in 18 secs): user=<>, rip=my.SERVER.ip.addr, lip=127.0.0.1, TLS handshaking: SSL_accept() failed: error:14$
Feb 27 01:19:15 mydomain dovecot: master: Warning: Killed with signal 15 (by pid=1 uid=0 code=kill)
Feb 27 01:19:15 mydomain dovecot: anvil: Warning: Killed with signal 15 (by pid=1 uid=0 code=kill)
Feb 27 01:19:15 mydomain dovecot: ssl-params: Warning: Killed with signal 15 (by pid=1 uid=0 code=kill)
Feb 27 01:19:15 mydomain dovecot: config: Warning: Killed with signal 15 (by pid=1 uid=0 code=kill)
Feb 27 01:19:15 mydomain dovecot: auth: Error: read(anvil-auth-penalty) failed: EOF
Feb 27 01:19:15 mydomain dovecot: auth: Error: net_connect_unix(anvil-auth-penalty) failed: Permission denied
Feb 27 01:19:15 mydomain dovecot: auth: Warning: Killed with signal 15 (by pid=1 uid=0 code=kill)
Feb 27 01:19:15 mydomain dovecot: log: Warning: Killed with signal 15 (by pid=1 uid=0 code=kill)
Feb 27 01:19:22 mydomain dovecot: master: Dovecot v2.2.10 starting up for pop3, imap (core dumps disabled)
Feb 27 01:19:44 mydomain dovecot: imap-login: Disconnected (no auth attempts in 15 secs): user=<>, rip=my.SERVER.ip.addr, lip=127.0.0.1, TLS handshaking: SSL_accept() failed: error:14$
Feb 27 01:23:55 mydomain postfix/qmgr[30121]: 2C915811BD1C: from=<[email protected]>, size=5316, nrcpt=1 (queue active)
Feb 27 01:23:58 mydomain postfix/smtp[27144]: 2C915811BD1C: to=<address@domain_that_sends_to_this_addresson_server.com>, relay=none, delay=290245, delays=290241/0.02/3.6/0, dsn=4.4.3, status=deferred (Host or domain$
Feb 27 01:24:41 mydomain dovecot: config: Warning: NOTE: You can get a new clean config file with: doveconf -n > dovecot-new.conf
Feb 27 01:24:41 mydomain dovecot: config: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:26: 'imaps' protocol can no longer be specified (use protocols=imap). to disable n$
Feb 27 01:24:41 mydomain dovecot: config: Warning: NOTE: You can get a new clean config file with: doveconf -n > dovecot-new.conf
Feb 27 01:24:41 mydomain dovecot: config: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:26: 'imaps' protocol can no longer be specified (use protocols=imap). to disable n$
Feb 27 01:24:53 mydomain dovecot: imap-login: Disconnected (no auth attempts in 12 secs): user=<>, rip=my.SERVER.ip.addr, lip=127.0.0.1, TLS handshaking: SSL_accept() failed: error:14$
Feb 27 01:25:05 mydomain dovecot: imap-login: Aborted login (no auth attempts in 1 secs): user=<>, rip=my.DEVBOX.ip.addr, lip=my.SERVER.ip.addr, TLS, session=<Kdrl7QsQxwBi9AyF>
Feb 27 01:27:16 mydomain dovecot: master: Warning: Killed with signal 15 (by pid=1 uid=0 code=kill)
Feb 27 01:27:16 mydomain dovecot: anvil: Warning: Killed with signal 15 (by pid=1 uid=0 code=kill)
Feb 27 01:27:16 mydomain dovecot: log: Warning: Killed with signal 15 (by pid=1 uid=0 code=kill)
Feb 27 01:27:24 mydomain dovecot: master: Dovecot v2.2.10 starting up for pop3, imap (core dumps disabled)
Feb 27 01:27:24 mydomain dovecot: config: Warning: NOTE: You can get a new clean config file with: doveconf -n > dovecot-new.conf
Feb 27 01:27:24 mydomain dovecot: config: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:26: 'imaps' protocol can no longer be specified (use protocols=imap). to disable n$

编辑#4

根据 @Celada 的进一步说明,我telnet imap.mydomain.com 143在用于 Thunderbird 测试的本地开发盒中输入 , ,终端回复:

Trying my.SERVER.ip.addr...
Connected to imap.mydomain.com.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE STARTTLS LOGINDISABLED] Dovecot ready.    

接下来,我在 devbox 终端输入openssl s_client -CApath /etc/ssl/certs -starttls imap -port 143 -host imap.mydomain.com,终端通过打印出来回复您可以通过单击此文件共享网站的链接来阅读详细信息

我的完整的单击此链接可以在文件共享站点上读取 dovecot.conf

编辑#5

根据 @Celada 的建议,我t1 login USERNAME PASSWORD在 后输入. OK Pre-login capabilities listed, post-login capabilities have more.,终端回复如下:

* CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS SPECIAL-USE BINARY MOVE
t1 OK Logged in

然而,我随后重复了 Thunderbird 登录测试,并检查强制 Thunderbird 使用端口 143 和“普通密码”。当我这样做时,Thunderbird 强制将“自动检测”作为 SSL 选项,然后单击“重新测试”按钮会导致相同的错误消息:

"Thunderbird failed to find the settings for your email account."  

答案1

经过一些来回评论和聊天后,OP 的问题现已解决。 IMAP 服务器需要指定为imap.mydomain.com代替mydomain.com尽管由于某种原因,这仅在使用高级帐户设置进行设置时才有效,而不是使用帐户创建对话框。

除了提到这个针对特定情况的解决方案之外,我认为在回答这个问题时我能说的最有用的事情是列出一些关于该主题的通用故障排除技巧,希望它们对其他人稍后阅读本文有所帮助。

  • Thunderbird 的自动检测帐户设置功能非常出色,对于电子邮件帐户设置的黑暗时期来说是一个巨大的改进,当时 ISP 必须提供冗长的说明,包括从服务器类型(POP 或 IMAP)到端口号到身份验证协议的所有内容。在理想的情况下,用户只需要指定他们的电子邮件地址、密码,也许我猜还有服务器名称(这就是他们通过网络访问 gmail 所需的全部,毕竟......)。

    然而,当自动检测功能不起作用时,您几乎得不到任何有用的错误消息。 “Thunderbird 未能找到您的电子邮件帐户的设置”基本上没有任何意义。

    提示:当 Thunderbird 的自动检测功能不起作用时,不要在上面浪费时间,而是手动指定所有内容,直到它起作用为止。然后,一旦您让它工作,您就可以集中精力找出自动检测失败的原因,并可能修复它,以便它适用于下一个用户。

  • 如果可以的话,请始终使用 IMAP 端口 143。还有用于基于 SSL 的 IMAP 的端口 993,但所有相当现代的客户端和服务器都支持 STARTTLS,用于将未加密的连接升级为加密的连接,因此实际上不再需要担心 IMAP 的不同端口。如果可能,端口 143 上的连接将自动加密。

  • (与 IMAP 无关,但无论如何)如果可以的话,请始终使用 SMTP 端口 587。 SMTP 过去总是在端口 25 上完成,但 ISP 经常因为垃圾邮件而阻塞端口 25。端口 587 专门用于 MUA 和邮件服务器之间的 SMTP 通信,预计将根据需要支持 SMTP AUTH 和 STARTTLS,并且已经存在多年。很少需要担心将 MUA 配置为使用任何其他端口。

  • Dovecot 对待未加密连接和加密连接的方式有所不同,这也可能适用于本地连接(至localhost127.0.0.1::1)与远程连接。最常见的身份验证类型在未加密的远程连接上是不安全的,因此 Dovecot 不提供它们。

    因此,在通过命令行进行测试和调试时,为了最接近地模拟真实的MUA,请进行远程测试并使用STARTTLS对连接进行加密。否则,您可能会发现身份验证工作正常,telnet但仍然想知道为什么它在 MUA 上不起作用。

  • 使用telnet(对于未加密连接)或openssl s_client(对于加密连接)进行测试

    使用您尝试让 MUA 接受的相同主机名。如果您希望imap.mydomain.commail.mydomain.com或只是mydomain.com在 MUA 中指定为邮件服务器时工作,请从命令行使用相同的主机名进行测试。如果您收到主机名解析错误,您就知道问题出在 DNS 上。

    openssl s_client -starttls imap -port 143 -CApath /etc/ssl/certs -host <hostname>
    
  • 如果 Dovecot 服务器上配置的 SSL 证书有问题,Thunderbird 会发出警告,但仍允许您连接。如果完全无法连接,则可能不是证书问题。

    当然,一旦您准备好投入生产,您将需要使用由公认的证书颁发机构签名的证书,并且证书上的名称与 MUA 中配置的 IMAP 服务器名称相匹配。

  • 用于测试的有用 IMAP 命令。将这些输入到您打开的 IMAP 会话中telnet(未加密)或openssl s_client(加密)

    tag1 LOGOUT
    tag2 LOGIN <username> <password>
    tag3 CAPABILITIES
    tag4 LIST "" "*"
    

相关内容