Javamail and gmail

  • The following code throws an IndexOutOfBoundsException. Any idea why?

    Folder folder = store.getDefaultFolder(); folder = folder.getFolder("INBOX"); int totalMessages = folder.getMessageCount(); //totalMessages is 17000 folder.getMessages(16900, 16999) --- here I am trying to get the NEWEST 99 messages. 

This code throws an indexoutofbounds exception, although there are so many emails. What am I doing wrong?

  • folder.getMessages () - receive all emails from the 1st letter to the last. In my case, 17,000 !! How to receive emails, from the latest to the oldest? I just want to see the latest emails - about 100 of them. Is it possible?
+4
source share
2 answers

There are never magical meanings in the code, it just hurts you. Try:

 int messagesToDisplay = 100; folder.getMessages(totalMessages - messagesToDisplay , totalMessages); 

From JavaDoc, messages are identified using array 1, not 0.

Can you also add a stack trace.

+5
source

first open the folder in read or read_write mode.

 folder.open(Folder.READ_WRITE); 
0
source

All Articles