title: Read mail from office 365 in java
body: <p>I have to read mails from office 365 using below code but it's not connecting to the server:</p>
  
  <pre><code>private void init()
  {
      try{
          Properties smtpProps = new Properties();
          smtpProps.put("mail.host", "192.168.10.18");
          smtpProps.put("mail.port", "995");
          smtpProps.put("mail.transport.protocol", "imaps");  
  
          session = Session.getInstance(smtpProps,
                    new javax.mail.Authenticator() {
                      protected PasswordAuthentication getPasswordAuthentication() {
                          return new PasswordAuthentication("abc@abc.om","test");
                      }
                    });
              System.out.println("session = "+session);
  
         Store store = session.getStore("imaps");
         store.connect();
         Folder inbox = store.getFolder("INBOX");
         inbox.open(Folder.READ_WRITE);           
         Message messages[] = null;
         messages = inbox.search(new FlagTerm(new Flags(Flag.SEEN), false));
         System.out.println("leng = "+messages.length);
      }catch(Exception e)
      {
          e.printStackTrace();
      }
  }
  </code></pre>