title: IMAP access to mail office 365 with javamail
body: <p>I'm trying to read the emails in a folder of an email account Office365 using JavaMail 1.4 api.</p>
  
  <p>My code is:</p>
  
  <pre><code>    public static void main(String argv[]) throws Exception {
      // Get a Properties object
      Properties props = System.getProperties();
  
      // Get a Session object
      Session session = Session.getInstance(props, null);
  
      // Get a Store object
      Store store = null;
      Folder rf = null;
  
      if (CUR_MAIL_PROTOCOL != null)
          store = session.getStore("imap");
  
      // Connect
      if (CUR_MAIL_HOST != null || CUR_MAIL_LOGIN != null || CUR_MAIL_PWD != null)
          store.connect("outlook.office365.com", 993, "**MYEMAIL**", "**MYPASS**");
      else
          store.connect();
  
      // List namespace
      rf = store.getDefaultFolder();
  
      getFolderDetails(rf, true, "");
      if ((rf.getType() &amp; Folder.HOLDS_FOLDERS) != 0) {
          Folder[] f = rf.list("%");
          for (int i = 0; i &lt; f.length; i++)
              getFolderDetails(f[i], recursive, "    ");
      }
  
      store.close();
  }
  </code></pre>
  
  <p>My error is:</p>
  
  <pre><code>    Exception in thread "main" javax.mail.MessagingException: Connection timed out: connect;
    nested exception is: 
      java.net.ConnectException: Connection timed out: connect
      at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:298)
      at javax.mail.Service.connect(Service.java:234)
  </code></pre>
  
  <p>Thanks</p>
  
  <p>PS: Account Office365 using JavaMail 1.4 api</p>