javamail:在明确配置的imap和143时接收来自993的电子邮件?我正在使用getInstance()

时间:2015-10-15 10:19:06

标签: ssl javamail imap

我正在将我的Web项目部署到客户端环境,我们被告知不要使用SSL和IMAPS。所以我们配置了这些属性:

mail.recv.protocol=imap
mail.recv.port=143

但是根据客户端服务器日志,我们得到了这个例外:

 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:695) 
        at javax.mail.Service.connect(Service.java:345) 
        at javax.mail.Service.connect(Service.java:226) 

.....

并提供了其他信息,我们通过993连接,所以我们找不到证书`因为jvm要求它。但我们必须通过143连接。

使用这些代码我们进行连接。如您所见,我们没有使用getDefaultInstance()进行连接。

input = CorreoAction.class.getResourceAsStream("/config/properties/mail.properties"); //we load `prop` from file
        Properties prop = new Properties();
        prop.load(input);
.....
    prop1 = new Properties(); //we copy prop to prop1 for `store`
        prop1.setProperty("mail.imap.connectiontimeout", "5000");
        prop1.setProperty("mail.imap.timeout", "5000");
        prop1.setProperty("mail.imap.host", prop.getProperty("mail.recv.host"));
        prop1.setProperty("mail.imap.port", prop.getProperty("mail.recv.port"));
        prop1.setProperty("mail.imap.ssl.trust", "*");
        prop1.setProperty("mail.imap.auth.plain.disable", "false");

        sesion = Session.getInstance(prop1); //connect with sesion.

        store = sesion.getStore(prop.getProperty("mail.recv.protocol")); //imap, not imaps.
        store.connect(prop.getProperty("mail.recv.host"), prop.getProperty("mail.recv.user"), prop.getProperty("mail.recv.pass"));

所以,问题是:如果我们强迫它使用143和imap,为什么应用程序连接到993?

0 个答案:

没有答案