Broken Markup in HTML after Adding Mail Message to PST

image (3).png (1.4 MB)

While convert mail message to pst format html markup is broken

Thank you for posting the query. Please check the issue using the latest version of Aspose.Email. If the issue persists, please share the following:

  • input mail message file
  • code example you used
  • output PST file

Hi Andrey

I updated library to latest version and it doesn’t help (43.3 KB)

File targetFile = new File(String.format("%s.pst", PST_SCRIPTS));
	PersonalStorage storage = PersonalStorage.create(targetFile.getAbsolutePath(), 0);
	InputStream targetStream = new FileInputStream(MBOX_FILE);

	FolderInfo folder = storage.getRootFolder().addSubFolder(NodeNameUtils.getDownloadNodeName(new Date()));

	String mailBody = IOUtils.toString(targetStream,;

	var mailMessage = new MailMessage();
	mailMessage.setDate(new Date());
	folder.addMessage(MapiMessage.fromMailMessage(mailMessage, MapiConversionOptions.getUnicodeFormat()));

Thank you for the additional data. You should use MboxrdStorageReader class to migrate email messages from the MBOX file to the PST file as shown below:

MboxLoadOptions loadOptions = new MboxLoadOptions();
MboxrdStorageReader mboxReader = new MboxrdStorageReader(mboxFilePath, loadOptions);

MapiConversionOptions conversionOptions = MapiConversionOptions.getUnicodeFormat();

MailMessage mailMessage;
while ((mailMessage = mboxReader.readNextMessage()) != null)
    MapiMessage mapiMessage = MapiMessage.fromMailMessage(mailMessage, conversionOptions);

API Reference: MboxrdStorageReader class

But there is something wrong with your MBOX file, the final PST becomes empty. So I added a ticket with ID EMAILJAVA-34930 in our tracking system. Our development team will investigate this case. We will inform you of any progress.

the implementation you describe is not suitable for my process because i get message body from cloud storage in bytes

it can slow down the process if i convert each file to mbox and then to pst

var message = localMailRepository.getObject(downloadObject);
		var mailMessage = new MailMessage();
		mailMessage.setFrom(new MailAddress(message.getFrom()));

		try (final StorageObjectInputStream inputStream = storageService.get(
		) {
			String mailBody = IOUtils.toString(inputStream,;

		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			stateServerService.objectProcessingError(ex, message);
		folder.addMessage(MapiMessage.fromMailMessage(mailMessage, MapiConversionOptions.getUnicodeFormat()));

	try {
		zip.put(pst, pst.getName());
	} catch (IOException e) {
		log.error(e.getMessage(), e);
		log.error("Failed to finish actions chain: close zip > upload zip > markup uploaded files > cleanup", e);
	}finally {

In your first code snippet, the targetStream object contains a full EML message including headers. You cannot use it as a mail body only. If the ‘inputStream’ object in the second code snippet is the same case, you can add the message to the PST file as shown below:

MailMessage mailMessage = MailMessage.load(inputStream);
folder.addMessage(MapiMessage.fromMailMessage(mailMessage, MapiConversionOptions.getUnicodeFormat()));

API Reference: MailMessage class

More examples:
Loading and Saving Message
Creating and Setting Contents of Emails
Extracting Message Contents from Emails

thanks a lot