连接到IMAP javax.net.ssl.SSLException:无法识别的SSL消息

Sur*_*amy 0 java ssl imap exchange-server

我正在尝试使用以下程序连接到我的公司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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在关注异常

    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)
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个错误?当我连接到我的gmail帐户时,相同的代码工作(上面的来源评论),我能够通过我的程序连接和阅读消息.交换服务器端需要通过IMAP下载消息的任何设置?我已经在我的Exchange服务器上启用了IMAP.

Sur*_*amy 5

更改

    props.setProperty("mail.store.protocol", "imaps");
Run Code Online (Sandbox Code Playgroud)

    props.setProperty("mail.store.protocol", "imap");
Run Code Online (Sandbox Code Playgroud)

解决了这个问题