Why am I not able to connect to my mail box using JavaMail (IMAP protocol) and getting NO AUTHENTICATE failed error?

Viewed 1569

I am trying to connect to a mailbox through JavaMail IMAP protocol but I am unable to connect successfully.

  1. telnet is successful
  2. Able to configure outlook web client with same credentials
  3. Tried with latest JavaMail version of 1.6.2 (JDK7 version)
  4. Tried setting following property as well : mail.imap.auth.plain.disable=true
Properties props = System.getProperties();
props .setProperty("mail.store.protocol", "imap");
props .setProperty("mail.debug.auth", "true");
props .setProperty("mail.imap.ssl.enable", "true");
props .setProperty("mail.imap.auth.plain.disable", "true");
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(UserName, Password);
                }
            });
session.setDebug(true);
store = session.getStore("imap");
store.connect(ServerName, Port, UserName, Password);
DEBUG: setDebug: JavaMail version 1.6.2
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
DEBUG IMAP: mail.imap.fetchsize: 16384
DEBUG IMAP: mail.imap.ignorebodystructuresize: false
DEBUG IMAP: mail.imap.statuscachetimeout: 1000
DEBUG IMAP: mail.imap.appendbuffersize: -1
DEBUG IMAP: mail.imap.minidletime: 10
DEBUG IMAP: closeFoldersOnStoreFailure
2019-06-12 20:10:11 imap : Before connect
DEBUG IMAP: trying to connect to host "<mail-server>", port 993, isSSL true
* OK The Microsoft Exchange IMAP4 service is ready.
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=NTLM AUTH=GSSAPI SASL-IR UIDPLUS MOVE ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: NTLM
DEBUG IMAP: AUTH: GSSAPI
DEBUG IMAP: protocolConnect login, host=<mail-server>, user=username, password=<non-null>
DEBUG IMAP: mechanism PLAIN disabled by property: mail.imap.auth.plain.disable
DEBUG IMAP: mechanism LOGIN not supported by server
A1 AUTHENTICATE NTLM
+ 
DEBUG NTLM: type 1 message: 4E 53 50 00 01 00 00 00 03 A2 00 00 00 00 00 00 2F 00 00 00 0F 00 0F 00  
<NTLMSSL encoded data>
A1 NO AUTHENTICATE failed.
DEBUG IMAP: trying to connect to host "<mail-server>", port 993, isSSL true
* OK The Microsoft Exchange IMAP4 service is ready.
B0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=NTLM AUTH=GSSAPI SASL-IR UIDPLUS MOVE ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
B0 OK CAPABILITY completed.
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: NTLM
DEBUG IMAP: AUTH: GSSAPI
DEBUG IMAP: protocolConnect login, host=<mail-server>, user=username, password=<non-null>
DEBUG IMAP: mechanism PLAIN disabled by property: mail.imap.auth.plain.disable
DEBUG IMAP: mechanism LOGIN not supported by server
B1 AUTHENTICATE NTLM
+ 
DEBUG NTLM: type 1 message: 4E 54 4C 53 45 4F 4C 56 41 44 53 52 56 30 39 31 
<NTLMSSL encoded data>
B1 NO AUTHENTICATE failed.
javax.mail.AuthenticationFailedException: AUTHENTICATE failed.
        at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:732)
        at javax.mail.Service.connect(Service.java:388)
        at com.maildebug.MailDebugUtil.Pop3_IMAP(MailDebugUtil.java:131)
        at com.maildebug.MailDebugUtil.main(MailDebugUtil.java:67)
2 Answers

You're almost certainly running into the Exchange server bug where it advertises that it support PLAIN authentication but it really doesn't.

The debug output doesn't show that you've disabled PLAIN authentication, perhaps you've done something wrong with how you're setting that property? Can you include the code you're actually using that shows how you've set the property?

Note also that you don't need the Authenticator.

The IMAP protocol changed to IMAPI4 due to which exchange server stopped communicating and lead to this issue. We have reverted these changes. Now, the issue got solved.

Related