javax.mail.AuthenticationFailedException: LOGIN failed

Occasional Visitor

We are facing issues to connect to the Office365 mailbox from java class on/from DB server(Oracle following error is thrown

javax.mail.AuthenticationFailedException: LOGIN failed.
        at com.sun.mail.imap.IMAPStore.protocolConnect(
        at javax.mail.Service.connect(

1. The same code on other server is failing for the same mailbox.
2. The same code on the same server is failing for other similar      mailbox.
3. for connect,resolve for      are enabled to the DB user
4. Port = 993, protocol = IMAP, server=, JDK on DB server: 1.6.0_43, JavaMail Version tried 1.3.2  / 1.3.5  / 1.5.6

Following is the code used to set IMAP properties:
       private Properties getIMAPProperties(String protocol, int port)
               Properties props = System.getProperties();
               props.put("", "");
               final String SSL_FACTORY = "";

               if (protocol.equalsIgnoreCase("IMAP") || protocol.equalsIgnoreCase("IMAPS"))
                       // Set manual Properties
                       props.setProperty("mail.imap.socketFactory.class", SSL_FACTORY);
                       props.setProperty("mail.imap.socketFactory.fallback", "false");
                       props.setProperty("mail.imap.port", "993");
                       props.setProperty("mail.imap.socketFactory.port", "993");
                       props.setProperty("mail.imap.auth.plain.disable", "true");
                       props.setProperty("mail.imap.auth.gssapi.disable", "true");
                       props.setProperty("mail.imap.auth.ntlm.disable", "true");
                       props.setProperty("mail.imap.ssl.enable", "true");
              return props;

Below is the excerpt of the Store usage in the Java code on DB server
 import javax.mail.Store;
 Store store = null;
 store = session.getStore(protocol.toLowerCase()); --protocol = IMAP
 store.connect(server, port, username, password);  --ERROR is thrown at this step

1 Reply
I encountered the same problem, how to solve it