简体   繁体   中英

Connecting to IMAP javax.net.ssl.SSLException: Unrecognized SSL message

I am trying to connect to my company IMAP server using following program but I am getting 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();
        }
    }
}

I am getting following Exception

    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)

How can I resolve this error? The same code works when I connect to my gmail account(source commented above), I am able to connect and read messages through my program. Any setting required at exchange server end to download messages through IMAP? I already have IMAP enabled on my exchange server.

Changing

    props.setProperty("mail.store.protocol", "imaps");

to

    props.setProperty("mail.store.protocol", "imap");

resolved the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM