Java Mail API- Reading OUTLOOK mails


Java Mail API- Reading OUTLOOK mails

Using JAVA Mail API for reading mails has been common these days. It’s pretty easy to use. Over the internet you can get boilerplate codes for reading mails from GMAIL or YAHOO, however I find a bit tricky when it comes to reading mails from OUTLOOK. GMAIL and YAHOO provides settings feature where you can turn ON for third-party apps access, whether POP3 or IMAP. But, for OUTLOOK the settings feature lets you handle POP3 only and these days developers prefer IMAP for reading mails. So, let me provide you some extra pieces of codes that lets you do IMAP access for OUTLOOK mails.

String protocol="imaps";
Properties props = new Properties();
props.setProperty("", protocol);
//extra codes required for reading OUTLOOK mails during IMAP-start
	props.setProperty("mail.imaps.socketFactory.class", "");
	props.setProperty("mail.imaps.socketFactory.fallback", "false");
	props.setProperty("mail.imaps.port", "993");
	props.setProperty("mail.imaps.socketFactory.port", "993");
//extra codes required for reading OUTLOOK mails during IMAP-end
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore(protocol);
store.connect("", emailAddress, password);
Folder inbox = store.getFolder("INBOX");;

//search for all "unseen" messages
Flags seen = new Flags(Flags.Flag.SEEN);
FlagTerm unseenFlagTerm = new FlagTerm(seen, false);
Message messages[] =;

About Anoop Kumar Rai