I am writing some code that generates a PST from EML files. Using Aspose.Email, as far as I can tell, the only way for me to get the EML into the PST is to
1) Read the EML from disk into MailMessage
2) Save the EML as a MSG using MailMessage.Save
3) Read the MSG from disk
4) Add the MSG to a PST
It would be nice if I could just
1) Read the EML from disk
2) Add the EML to a PST
so that I can skip the step of having to write out the temporary MSG file.
Hi,
pst.getRootFolder().addSubFolder(“EmailTestFolder”).addMessage(MapiMessage.fromMailMessage(MailMessage.load(“test.eml”)));
Please write back in case of any ambiguities or comments.
So when I try to add it directly, using similar code to what you provided, the resulting emails within the newly created PST are “corrupted”. When looking at them in summary view, you can’t see some of the information (sender, date, etc.). These are EMLs that I have validated using MailMessage.validateMessage().
However, when I first write them to disk as MSG and then reload the MSG and add that to the PST, everything looks great.
This DOES work:
folder = pst.getRootFolder().addSubFolder(FOLDER_NAME);
sourceEmlPath = f.getAbsolutePath();
EmlValidationErrorCollection emlValidationErrorCollection = MailMessage.validateMessage(sourceEmlPath);
if (emlValidationErrorCollection.size() > 0) {
validationErrors++;
}
MailMessage mailMessage = MailMessage.load(sourceEmlPath, MessageFormat.getEml());
File tmpMsgFile = TempFileManager.createTempFile("pst-exporter-" + UUID.randomUUID().toString(), ".msg");
mailMessage.save(tmpMsgFile.getAbsolutePath(), MailMessageSaveType.getOutlookMessageFormatUnicode());
MapiMessage mapiMessage = MapiMessage.fromFile(tmpMsgFile.getAbsolutePath());
try {
folder.addMessage(mapiMessage);
} catch (Exception e) {
e.printStackTrace();
}
tmpMsgFile.delete();
This DOES NOT work:
pst = PersonalStorage.create("/data/sample.PST", FileFormatVersion.Unicode);
folder = pst.getRootFolder().addSubFolder(FOLDER_NAME);
sourceEmlPath = f.getAbsolutePath();
EmlValidationErrorCollection emlValidationErrorCollection = MailMessage.validateMessage(sourceEmlPath);
if (emlValidationErrorCollection.size() > 0) {
validationErrors++;
}
try {
folder.addMessage(MapiMessage.fromMailMessage(MailMessage.load(sourceEmlPath, MessageFormat.getEml())));
} catch (Exception e) {
e.printStackTrace();
}
Hi,
I was using Aspose.Email 1.8.0 for Java, but this morning I have downloaded 1.9.0 and am using it.
Unfortunately, I still get the same behavior. I copy/pasted your code and used the attached EML. When attempting to open the new PST in Microsoft Office I see the message but it is missing some metadata, and then immediately Outlook crashes.
You will find attached…
Screenshot of Outlook Version
Screenshot of Outlook opened to the sample PST
The sample source EML
Hi,