This is the code :
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", "****@gmail.com", "****");
System.out.println(store);
Folder folder = store.getDefaultFolder();
folder = folder.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
System.out.println("Message Count: "+folder.getMessageCount());
System.out.println("Unread Message Count: "+folder.getUnreadMessageCount());
Message[] messages = folder.getMessages(); --> here the code stops.
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
folder.fetch(messages, fp);
for (int i = 0; i< messages.length; i++)
{
System.out.println("From:"+ messages[i].getFrom());
}
The code gives out the following excption and stops at the point shown.
Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource at com.google.code.com.sun.mail.imap.MessageCache.getMessage(MessageCache.java:129) at com.google.code.com.sun.mail.imap.IMAPFolder.getMessage(IMAPFolder.java:1394) at openReports.OpenReports.main
I added activation.jar to buildpath and the problem is solved.
So i used 2 jars java-mail-ima.** .jar, activation.jar (for further referebces).
In case you use maven you can add manually
I solved a similar NoClassDefFoundError: javax/activation/DataSource problem in a mixed Java/Scala project by switching to Java 8 (it was Java9 by default).
Discussion: https://github.com/highsource/jsonix-schema-compiler/issues/81