Free Support Forum -

Converting from PST to EML - Java


I’m currently evaluating Aspose Email for Java and I’m looking for a way to extract messages from a PST directly into EML. I’ve been able to extract messages from a PST in MSG format, and then convert from MSG to EML, but this involves writing the MSG file to disk and then reading it back in.

Is there a way to convert from PST to EML without having to first write a MSG to disk?

Thanks in advance.


I’ve found a way around it but it feels like a bit of a hack…

Instead of saving the MSG file to disk I write it to a ByteArrayOutputStream. I then read that ByteArrayOutputStream back in to a ByteArrayInputStream which I can pass in to create an eml.

ByteArrayOutputStream msgOutputStream = new ByteArrayOutputStream();;

InputStream msgInputStream = new ByteArrayInputStream(msgOutputStream.toByteArray());
MailMessage msg = MailMessage.load(msgInputStream, MessageFormat.getMsg()); “new_message_file.eml”, MailMessageSaveType.getEmlFormat());

Hi Bradley,

Thank you for using Aspose.Email.

Your method is also right, but usually from MapiMessage to MailMessage conversion, the following code sample can be used:

Sample Code:

PersonalStorage pst = PersonalStorage.fromFile(“Outlook.pst”);<o:p></o:p>

FolderInfo folderInfo = pst.getPredefinedFolder(StandardIpmFolder.Inbox);

MessageInfoCollection coll = folderInfo.getContents();

for (int i=0;i<coll.size();i++)


MessageInfo msgInfo = (MessageInfo)coll.get(i);

MapiMessage mapi = pst.extractMessage(msgInfo);


.getInstance().getIntepretor( mapi.getMessageClass() )

.interpret(mapi).save("DestFolder//" + i+".eml", MessageFormat.getEml() );


Please let us know if we can be of any additional help to you in this regard.

That works perfectly, thanks very much. I was hoping there would be a way to perform the conversion like this.


. getInstance ().getIntepretor( mapi.getMessageClass() )

.interpret(mapi).save(“DestFolder//” + i+".eml", MessageFormat. getEml () );

This Code is not working in 18.9, is there any different method to use “MailMessageInterpretorFactory” class.


Please use the code snippet given below to save EML file.

MapiMessage mapi = pst.extractMessage(messageInfo);"DestFolder\\" + i + ".eml", EmlSaveOptions.getDefaultEml());

We hope that this answered you question. Please feel free to reach us if additional information is required.