通过 Javamail 阅读邮件时连接超时

Connection timeout while reading mails via Javamail

我正在尝试使用 Javamail api 从我们的邮件服务器读取邮件。该程序在 运行 在我的本地系统上的 windows eclipse 上工作正常。 当我将相同的代码移动到我们的 linux 环境时,出现连接超时错误。

我需要在 linux 上安装一些软件包吗?我认为端口应该打开,否则我将无法从我的本地网络连接?

我使用的代码如下:

properties.setProperty("mail.store.protocol", "imaps");
properties.put("mail.imaps.ssl.trust", "*");
session = Session.getInstance(properties, null);
store = session.getStore();
store.connect(mailServerName, userName, password);

您必须首先检查您是否允许从您的 lunix 主机连接到您的邮件服务器,通过发出 telnet 像这样:telnet host port命令,有时它被防火墙阻止或网络杀毒。你也可能在代理服务器后面(你必须与你的网络管理员一起检查以上所有内容)。

如果您在代理服务器后面,则必须为 JVM 设置代理设置和凭据。为此,请查看 Chris Carruthers answer 中的答案 这里。