Javamail如何连接到IMAP邮件服务器,而无需证书验证

问题描述 投票:0回答:1

我正在尝试在测试环境中将Java应用程序连接到993上的IMAP服务器邮件。

我正在尝试忽略证书验证,使用先前对类似问题的答案的建议,如下所示:

imapProps.put("mail.imaps.ssl.checkserveridentity", "false");
imapProps.put("mail.imaps.ssl.trust", "*");

但是它似乎不起作用,我仍然遇到异常。

Cannot process current mailbox => sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
javax.mail.MessagingException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target;
  nested exception is:
    javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:727)

所以我的问题是,实际上可以使用IMAPS协议连接到邮件服务器,而无需检查或验证证书吗?

如果是,选择忽略证书验证,那不是两方面的决定吗? JavaApp和mailServer吗?

ssl certificate javamail imap
1个回答
0
投票

您需要在属性和getStore方法调用中使用相同的协议名称。因此,由于要设置imaps属性,因此应使用Store s = session.getStore("imaps");

© www.soinside.com 2019 - 2024. All rights reserved.