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

Free Support Forum - aspose.com

When MailMessage.getBody returns HTML version and when it return text version?

I have two pipelines use the same byte[] content as input.

  1. One output the content to Mbox file, then use mboxreader to read it in MailMessage and add to a pst file. Then read the MailMessage from the pst file and print its body
    code:

//read from inputstream the mbox file which contains the content
MboxrdStorageReader mboxReader = new MboxrdStorageReader(new FileInputStream("/tmp/content.mbox", true)
MailMessage message = mboxReader.readNextMessage()

PersonalStorage pst = PersonalStorage.create(new FileOutputStream("/tmp/test.pst"), 0)
pst.addSubFolder(“inbox”);
pst.addMessage(mailMessage, “inbox”);
pst.close();

// read the message
pst = PersonalStorage.fromStream(new FileInputStream("/tmp/test.pst"), false)
FolderInfo folder = pst.getRootFolder().getSubFolder(“inbox”);
for (MessageInfo messageInfo : folder.getContents()) {
MapiMessage mapiMessage = pst.extractMessage(messageInfo);
MailConversionOptions conversionOptions = new MailConversionOptions();
conversionOptions.setKeepOriginalEmailAddresses(true);
conversionOptions.setPreserveEmbeddedMessageFormat(true);
MailMessage mailMessage = mapiMessage.toMailMessage(conversionOptions);
System.out.println(mailMessage.getBody());
}

  1. the second loads the byte[] content into pst directly and then read its message and print the body

MailMessage mailMessage = MailMessage.load(new ByteArrayInputStream(contents));
PersonalStorage pst = PersonalStorage.create(new FileOutputStream("/tmp/test.pst"), 0)
pst.addSubFolder(“inbox”);
pst.addMessage(mailMessage, “inbox”);
pst.close();

rest read logic is the same as one

However, the output message body in 1 and 2 are different, 1 is text body, 2 is html body.

I suppose MailMessage.getBody will internally call MailMessage.getHtmlBody as a condition and I want to know in what condition it returns html body , and in what condition it returns text body. The message content byte[] input is the same.

@jiarongl,
Thank you for the query. I will answer you as soon as possible.

@jiarongl,
Unfortunately, we cannot use your code snippets containing unknown symbols (addSubFolder, addMessage, contents). Please check the issue with the latest version of Aspose.Email.

If the issue persists, please share the following:

  • “content.mbox” and “test.pst” files
  • comprehensive code examples demonstrating the problems
  • screenshots of the problems