1

I have code that connects to gmail and reads all emails. I then loop each message and parse for some data.

Below is the code that connects and downloads emails.

  ImapMailReceiver receiver = new ImapMailReceiver("imaps://"+mailAccount.box+":"+ URLEncoder.encode(mailAccount.pw,"utf-8")+"@imap.gmail.com:993/INBOX");

    receiver.setShouldMarkMessagesAsRead(false);
    receiver.setShouldDeleteMessages(false);
    receiver.setMaxFetchSize(200);
    receiver.afterPropertiesSet();

    Message[] receive = receiver.receive();

The issue is - first time I run the program with given userid/pwd, it works fine and downloads emails. I run the code again from second time onwards, it doesn't download any emails. I guess it looks for newer emails after my previous download.

How do I download all the emails everytime I run the code.

0 Answers0