我正在尝试使用以下代码在端口 443 上使用 IMAPS 连接到交换服务器(在另一端已以这种方式配置):. .
props.setProperty("javax.net.ssl.trustStore", "C:/Program Files/Java/jdk1.6.0_30/jre/lib/security/cacerts");
props.setProperty("javax.net.ssl.trustStorePassword", "changeit");
props.setProperty("javax.net.ssl.trustStoreType", "jks");
props.setProperty("javax.net.debug", "ssl");
System.setProperties(props);
props = System.getProperties();
final Session session = Session.getInstance(props, null);
session.setDebug(debug);
com.sun.mail.imap.IMAPFolder inbox = null;
Store store = null;
store = session.getStore("imaps");
store.connect(host, 443, username, password);
inbox = (com.sun.mail.imap.IMAPFolder) store.getFolder("INBOX");
. . .
从我没有收到证书错误的事实来看,它们是从商店位置正确加载的。但是,一旦代码到达连接语句,我就会得到以下跟踪:"
[29/01/13 18:23:02:811 CST] 0000007d SystemOut O DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc]
[29/01/13 18:23:02:812 CST] 0000007d SystemOut O DEBUG: mail.imap.fetchsize: 16384
[29/01/13 18:18:42:814 CST] 0000007d SystemErr R javax.mail.MessagingException;
nested exception is:
java.io.IOException
[29/01/13 18:18:42:814 CST] 0000007d SystemErr R at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:479)
[29/01/13 18:18:42:814 CST] 0000007d SystemErr R at javax.mail.Service.connect(Service.java:275)
[29/01/13 18:18:42:814 CST] 0000007d SystemErr R at com.scots.utils.MailPoller$1.run(MailPoller.java:74)
[29/01/13 18:18:42:815 CST] 0000007d SystemErr R at java.lang.Thread.run(Thread.java:738)
[29/01/13 18:18:42:815 CST] 0000007d SystemErr R Caused by: java.io.IOException
[29/01/13 18:18:42:815 CST] 0000007d SystemErr R at com.sun.mail.iap.ResponseInputStream.read0(ResponseInputStream.java:99)
[29/01/13 18:18:42:815 CST] 0000007d SystemErr R at com.sun.mail.iap.ResponseInputStream.readResponse(ResponseInputStream.java:67)
[29/01/13 18:18:42:815 CST] 0000007d SystemErr R at com.sun.mail.iap.Response.<init>(Response.java:83)
[29/01/13 18:18:42:815 CST] 0000007d SystemErr R at com.sun.mail.imap.protocol.IMAPResponse.<init>(IMAPResponse.java:48)
[29/01/13 18:18:42:815 CST] 0000007d SystemErr R at com.sun.mail.imap.protocol.IMAPResponse.readResponse(IMAPResponse.java:122)
[29/01/13 18:18:42:815 CST] 0000007d SystemErr R at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:230)
[29/01/13 18:18:42:815 CST] 0000007d SystemErr R at com.sun.mail.iap.Protocol.<init>(Protocol.java:91)
[29/01/13 18:18:42:815 CST] 0000007d SystemErr R at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:87)
[29/01/13 18:18:42:815 CST] 0000007d SystemErr R at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:446)
[29/01/13 18:18:42:816 CST] 0000007d SystemErr R ... 3 more
没有别的!我到处搜索在连接执行期间抛出 IOException 的可能含义或原因,但到目前为止我一无所获。
鉴于堆栈跟踪没有更进一步,并且我自己的代码中引用的唯一行是连接语句本身(com.scots.utils.MailPoller$1.run(MailPoller.java:74),我真的不有很多事情要做。
唯一想到的可能会引起麻烦的是,我已将邮件轮询机制放在另一个线程中(运行方法)。会不会惹麻烦?
您可以提供的任何想法将不胜感激!
提前致谢。