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
In case you use maven you can add manually
<dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> <version>1.1.1</version> </dependency>
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With