Converting MapiMessage to MailMessage Produces Corrupted Result

Hi,


We use MapiMessage in all our operations for working with message properties and then need to convert it to EML. Currently, we save the MapiMessage to memorystream and then load MailMessage from it for saving to EML. Is it the right way, as we get corrupt output files in result.

Hi Robert,


Thank you for writing to Aspose Support team.

The proper way to convert MapiMessage to EML is using the Interpret method of MailMessageInterpretor as shown in the following code sample. Please try it at your end and let us know your feedback if you face any issue while using this conversion method.

Sample Code:

MapiMessage mapiMsg = MapiMessage.FromFile(“some msg file.msg”);

MailMessageInterpretor mi = MailMessageInterpretorFactory.Instance.GetIntepretor(mapiMsg.MessageClass);

MailMessage mailMsg = mi.Interpret(mapiMsg);

mailMsg.Save(“save as EML.eml”);

MapiMessage mapiMsg = MapiMessage.FromFile(“some msg file.msg”);

MailMessageInterpretor mi = MailMessageInterpretorFactory.Instance.GetIntepretor(mapiMsg.MessageClass);

MailMessage mailMsg = mi.Interpret(mapiMsg);

mailMsg.Save(“save as EML.eml”);

This Code is not working in java.18.9.4 email

@pradeepnegi,

Thank you for contacting Aspose Support.
Please use the code snippet given below to convert MSG to EML.

MapiMessage mapiMsg = MapiMessage.fromFile("Email.msg");
mapiMsg.save("Email.eml", EmlSaveOptions.getDefaultEml());

We hope that this resolved the issue that you were facing. Please feel free to reach us if additional information is required.

Hello @muhammadahmad,
The above code snippet works good, but I just want to convert MapiMessage to MailMessage, not to save it. I intend to use all the methods provided in the MailMessage as I’m also working with other systems. Do I have to save the MapiMessage (as shown above) and load it again to get MailMessage?
I’m working with PST’s and I could only get MapiMessage out of pst using extractMessage method. I need MailMessage to get what I want from the email.

@VenkateshDharavath,
Welcome to our community! Thank you for posting the query. You can convert MapiMessage to MailMessage without saving it to a file as shown below:

MailConversionOptions options = new MailConversionOptions();
MailMessage mailMessage = mapiMessage.toMailMessage(options);

More examples: Loading and Saving Message
API Reference: MailMessage class, MapiMessage class, MailConversionOptions class