我正在尝试使用以下程序连接到我的公司IMAP服务器,但我收到了SSLException。
import javax.mail.*;
import java.util.Properties;
/**
* Created by SDuraisamy on 6/18/2014.
*/
public class Test {
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
Session session = Session.getInstance(props, null);
Store store = null;
try {
store = session.getStore();
// store.connect("imap.gmail.com","mygmailaccount@gmail.com","password");
store.connect("exchange_server", "account2", "password");
Folder inbox = store.getFolder("INBOX");
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
我正在接受以下异常
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:670)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at Test.main(Test.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRecord.java:523)
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:355)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789)
如何解决此错误?
当我连接到我的gmail
帐户(上面评论的来源)时,相同的代码可以正常工作,我能够通过我的程序连接和阅读消息。
交换服务器端需要通过IMAP下载消息的任何设置?我已经在我的Exchange服务器上启用了IMAP。
答案 0 :(得分:5)
更改
props.setProperty("mail.store.protocol", "imaps");
到
props.setProperty("mail.store.protocol", "imap");
解决了问题