We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ImapClient: Try to save email from subfolder and getting wrong message (Java)


I want to save email from subfolder on mail server. Ex: Inbox/test
Screenshot from 2020-01-20 14-38-56.png (48.8 KB)

I follow Aspose document but the mail that be saved is not from test folder. It’s a mail from Inbox instead.
As I print it out, data from ImapMessageInfo seem right. But when I try to fetch message from ImapClient by unique id, the list is all messages from Inbox and I cannot find the way to filter the list.
Could you please advice a way to fix this issue?
Here is my JAVA code:

		ImapClient client = new ImapClient();

		ImapMessageInfoCollection coll = client.listMessages("Inbox/test", true);

		for (ImapMessageInfo msgInfo : coll) {
			System.out.println("Message Subject: " + msgInfo.getSubject());
			System.out.println("From: " + msgInfo.getSender().getAddress());
			System.out.println("Sent Date: " + msgInfo.getDate());
			System.out.println("Mime Message Id: " + msgInfo.getMessageId());
			MailMessage eml = client.fetchMessage(msgInfo.getUniqueId());
			eml.save(new File(folderTarget, eml.getSubject()) + ".eml", SaveOptions.getDefaultEml());
			eml.save(new File(folderTarget, eml.getSubject()) + ".msg", SaveOptions.getDefaultMsg());



I have observed your requirements and suggest you to please visit the following thread link for your kind reference. I also like to share that you need to traverse the mailbox folder wise to avoid get the exact folder message.


Thanks for your advice. Actually my code followed these Aspose’s example as your link. Somehow when I run my code again today the previous problem is gone. I’m not sure why.
But I have a new problem. I cannot fetch messages, some of them return null and I got NullPointerException. Same code, I don’t edit anything.


It’s strange that using same code your previous issue is gone and now you are facing other issue of NullPointerException on fetching message. I request you to please provide a working sample project along with test account credentials reproducing the issue so that we may proceed further with investigation on our end.

Here is the sample project as you requested. The zip file is protected, I’ll send the password to your inbox message.
sample.zip (22.9 KB)

@rcomniscien ,

Can you please confirm if the shared project is reproducing the issue related to NullPointerException on fetching messages?

I confirm. I tested it before provided it to you and here is the result when I run it again today, still got NullPointerException.
Screenshot from 2020-01-23 09-33-04.png (451.4 KB)


Thank you for sharing the clarification. An issue with ID EMAILJAVA-34648 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.