Hi,
I am using javamail to retrieve incoming mails. With the below code it's taking 4.5 to 5 sec to receive 23 emails.
To connect to the store it's taking 3.5 to 4 seconds.
I have checked with thunderbird, mails receive in milli seconds.
Is there a way to reduce time?
How much time does it take usually to receive 25 mails using imaps?
Properties properties = new Properties();
properties.put("mail.store.protocol", "imaps");
properties.put("mail.host", host);
properties.put("mail.port", "993");
// properties.put("mail.imaps.fetchsize", "3000000");
properties.put("mail.imaps.ssl.enable", "true");
Session emailSession = Session.getInstance(properties);
Store store = emailSession.getStore("imaps");
if(!store.isConnected()){
System.out.println("not connected");
store.connect(username, pwd);//Here takes 3.5 to 4 seconds
System.out.println("time taken store connect: "+System.currentTimeMillis());
}System.out.println("connected");
// create the folder object and open it
Folder emailFolder =store.getFolder("INBOX");
emailFolder.open(Folder.READ_WRITE);
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(IMAPFolder.FetchProfileItem.FLAGS);
fp.add(IMAPFolder.FetchProfileItem.CONTENT_INFO);
fp.add(UIDFolder.FetchProfileItem.UID);
emailFolder.fetch(emailFolder.getMessages(), fp); // Load the profile of the messages in 1 fetch.
// emailFolder.doCommand(new CustomProtocolCommand(start, end));
for (final Message message : emailFolder.getMessages()) {
System.out.println("message"+message.getSubject());//Here takes 4.5 to 5 seconds
System.out.println("time taken message: "+System.currentTimeMillis());
}