title: How to connect to office365 using IMAPS protocol from Java application
body: <p>There are few articles out there about this, but non of them worked for me. Basically I have following java code to connect to office 365:</p>
  
  <pre><code>  Properties props = new Properties();
    props.put("mail.imaps.auth.plain.disable", "true");
    props.put("mail.imaps.ssl.enable", "true");
  
    session = Session.getInstance(props, null);
    store = session.getStore("imaps");
    store.connect("outlook.office365.com", 993, "user@mydomain.com", "psw");
  </code></pre>
  
  <p>but it fails with LOGIN failed error;</p>
  
  <pre><code>javax.mail.AuthenticationFailedException: LOGIN failed.
          at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:725)
          at javax.mail.Service.connect(Service.java:366)
  </code></pre>
  
  <p>Also I'm able to login into my account using IMAPS from Thunderbird.</p>
  
  <p>Any pointers to resolve an issue would be appreciated!</p>