我正在尝试使用以下程序连接到我公司的 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 下载消息需要在交换服务器端进行任何设置吗?我的交换服务器上已经启用了 IMAP。
最佳答案
改变
props.setProperty("mail.store.protocol", "imaps");
到
props.setProperty("mail.store.protocol", "imap");
解决了问题
关于java - 连接到 IMAP javax.net.ssl.SSLException : Unrecognized SSL message,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24276191/