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

Free Support Forum - aspose.com

Distribution List Problems

I’m having problems when dealing with Distribution and Contacts out of a PST file.
When I export the items from the PST and save them to disk, the appear to be corrupted. I can open them with Aspose but I can’t open them with MFCMapi tool. When I open the items with Aspose I iterate through the properties but they don’t have the same values as when I open the original with MFCMapi.

I have attached the PST that I am testing with. I am using the Java API version

Below is the code snippet that I’m using to extract the items. I’m using the enumerateMessageEntryId method to loop through the items and then just saving them to disk.

private int extractFolder(PersonalStorage pst, FolderInfo folderInfo, String unpackDirectory, int currentElementCount) throws FileNotFoundException {

unpackDirectory = unpackDirectory + File.separator + folderInfo.getDisplayName();
new File(unpackDirectory).mkdirs();

for(String mapiEntryId : folderInfo.enumerateMessagesEntryId()) {
String fileName = removeIllegalFileNameCharacters(mapiEntryId);
File file = new File(unpackDirectory + File.separator + fileName + “.msg”);

pst.saveMessageToStream(mapiEntryId, new FileOutputStream(file));

if(folderInfo.hasSubFolders()) {
for(FolderInfo folder : folderInfo.enumerateFolders()) {
currentElementCount = extractFolder(pst, folder, unpackDirectory, currentElementCount);

return currentElementCount;

Hi Christopher,

Thank you for posting your inquiry.

We have tested your sample PST file with the latest version of Aspose.Email for Java API v 6.0.0 and the items in the Contacts folder are exported without any issue. These can be opened fine in MS Outlook as well without any error. Please try it with this latest version and share your feedback with us.


I have tested this with the latest 6.0.0 version and still find that the items inside the PST are corrupt when exported. I have attached the code that I used to test this PST and you’ll notice that it extracts the items using 2 different methods. This is what I have found:

Using these for-loop constructs

  1. for(MapiMessage mapi : folderInfo.enumerateMapiMessages()) – Works!!!
  2. for(String mapi : folderInfo.enumerateMessagesEntryId()) – Corrupt Email

It seems that when I use the first for-loop construct I get a MapiMessage. If I use the MapiMessage.save(fileName), then the object seems to be complete and isn’t corrupted.

If I use the second for-loop construct I get a Id as a String. I then use the method pst.saveMessageToStream(entryId, new FileOutputStream(emailFileName)). This seems to result in a corrupted MSG object that I cannot open in MFCMapi or Outlook.

My guess is that your internal implementation of the stream is not being flushed and closed properly (but that is just a guess). Ultimately I need to use the second option for performance reasons.



Hi Chirstopher,

Thank you for sharing the additional details.

We were able to reproduce the problem with SaveMessageToStream and have logged it as EMAILJAVA-33557 in our bug tracking system. We shall notify you here once there is some information available about this problem.