我正在完成检索电子邮件的任务.我设法使用以下代码检索.但是,它从gmail收件箱中的最早到最新的电子邮件中检索收到的电子邮件.有没有办法让它检索到最新的邮件?我打算实现一种方法来检索最新的20封邮件,而不是检索收件箱中的所有邮件.提前感谢您的指导.
public ArrayList<HashMap<String, String>> getMail(int inboxList){
Folder inbox;
/* Set the mail properties */
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
try
{
/* Create the session and get the store for read the mail. */
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com",username, password);
/* Mention the folder name which you want to read. */
inbox = store.getFolder("Inbox");
System.out.println("No of Unread Messages : " + inbox.getUnreadMessageCount());
/*Open the inbox using store.*/
inbox.open(Folder.READ_WRITE);
/* Get the messages which is …Run Code Online (Sandbox Code Playgroud)