javax.mail.AuthenticationFailedException: LOGIN failed

%3CLINGO-SUB%20id%3D%22lingo-sub-125407%22%20slang%3D%22en-US%22%3Ejavax.mail.AuthenticationFailedException%3A%20LOGIN%20failed%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-125407%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20are%20facing%20issues%20to%20connect%20to%20the%20Office365%20mailbox%20from%20java%20class%20on%2Ffrom%20DB%20server(Oracle%2011.2.0.4.0).The%20following%20error%20is%20thrown%3C%2FP%3E%3CP%3E%3CSTRONG%3Ejavax.mail.AuthenticationFailedException%3A%20LOGIN%20failed.%3C%2FSTRONG%3E%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20at%20com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20at%20javax.mail.Service.connect(Service.java)%3C%2FP%3E%3CP%3E1.%20The%20same%20code%20on%20other%20server%20is%20failing%20for%20the%20same%20mailbox.%3CBR%20%2F%3E2.%20The%20same%20code%20on%20the%20same%20server%20is%20failing%20for%20other%20similar%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20mailbox.%3CBR%20%2F%3E3.%20java.net.SocketPermissions%20for%20connect%2Cresolve%20for%20outlook.office365.com%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20are%20enabled%20to%20the%20DB%20user%3CBR%20%2F%3E4.%20Port%20%3D%20%3CSTRONG%3E993%3C%2FSTRONG%3E%2C%20protocol%20%3D%20%3CSTRONG%3EIMAP%3C%2FSTRONG%3E%2C%20server%3D%20%3CSTRONG%3Eoutlook.office365.com%3C%2FSTRONG%3E%2C%20JDK%20on%20DB%20server%3A%20%3CSTRONG%3E1.6.0_43%3C%2FSTRONG%3E%2C%20JavaMail%20Version%20tried%20%3CSTRONG%3E1.3.2%26nbsp%3B%26nbsp%3B%2F%201.3.5%26nbsp%3B%20%2F%201.5.6%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EFollowing%20is%20the%20code%20used%20to%20set%20IMAP%20properties%3A%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20private%20Properties%20getIMAPProperties(String%20protocol%2C%20int%20port)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Properties%20props%20%3D%20System.getProperties()%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20props.put(%22mail.imap.host%22%2C%20%22outlook.office365.com%22)%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20final%20String%20SSL_FACTORY%20%3D%20%22javax.net.ssl.SSLSocketFactory%22%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if%20(protocol.equalsIgnoreCase(%22IMAP%22)%20%7C%7C%20protocol.equalsIgnoreCase(%22IMAPS%22))%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20Set%20manual%20Properties%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20props.setProperty(%22mail.imap.socketFactory.class%22%2C%20SSL_FACTORY)%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20props.setProperty(%22mail.imap.socketFactory.fallback%22%2C%20%22false%22)%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20props.setProperty(%22mail.imap.port%22%2C%20%22993%22)%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20props.setProperty(%22mail.imap.socketFactory.port%22%2C%20%22993%22)%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20props.setProperty(%22mail.imap.auth.plain.disable%22%2C%20%22true%22)%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20props.setProperty(%22mail.imap.auth.gssapi.disable%22%2C%20%22true%22)%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20props.setProperty(%22mail.imap.auth.ntlm.disable%22%2C%20%22true%22)%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20props.setProperty(%22mail.imap.ssl.enable%22%2C%20%22true%22)%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20return%20props%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EBelow%20is%20the%20excerpt%20of%20the%20Store%20usage%20in%20the%20Java%20code%20on%20DB%20server%3CBR%20%2F%3E%26nbsp%3Bimport%20javax.mail.Store%3B%3CBR%20%2F%3E%26nbsp%3BStore%20store%20%3D%20null%3B%3CBR%20%2F%3E%26nbsp%3Bstore%20%3D%20session.getStore(protocol.toLowerCase())%3B%20--protocol%20%3D%20IMAP%3CBR%20%2F%3E%3CSTRONG%3E%26nbsp%3Bstore.connect(server%2C%20port%2C%20username%2C%20password)%3B%26nbsp%3B%20--ERROR%20is%20thrown%20at%20this%20step%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-125407%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAuthenticationFailedException%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ejavax%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ejavax.mail%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ELOGIN%20failed%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Visitor

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

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

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. java.net.SocketPermissions for connect,resolve for outlook.office365.com      are enabled to the DB user
4. Port = 993, protocol = IMAP, server= outlook.office365.com, 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("mail.imap.host", "outlook.office365.com");
               final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

               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