Saving message from server as eml throws format exception


we are experiencing an issue where some emails fetched from server throw a format exception when saved to disk using DefaultEmlSaveOptions.

Stacktrace excerpt:

class An invalid character was found in the 7-bit stream.

We have found a workaround

  • saving the file to disk first as MHTML

  • load the file from disk using defaults

  • save the file to disk as EML

    SaveOptions saveOptions = null;
    try {
      saveOptions = SaveOptions.getDefaultEml();, saveOptions);
    } catch (FormatException formatException) {
      if (formatException.getMessage().contains("7-bit")) {
      	// START DS-585 workaround
      	saveOptions = SaveOptions.getDefaultMhtml();
      	((MhtSaveOptions) saveOptions).setMhtFormatOptions(MhtFormatOptions.NoEncodeCharacters);, saveOptions);
      	eml = MailMessage.load(filePath.toString());
      	saveOptions = SaveOptions.getDefaultEml();, saveOptions);
      	// END DS-585 workaround
      } else {
      	throw formatException;


This is quite a convoluted and inefficient way of saving a mailMessage to eml. Is this a bug in aspose, or is there a better way to save these emails as eml?

this zip contains two emails that are affected:

We are using for java 17.7




Thank you for contacting Aspose support team.

We have tried to reproduce the issue using sample EML but could not succeed. Following sample code is used for testing:

MailMessage mail1 =  MailMessage.Load(@"5211_4_1a_c89276fefa5213be971de324439ac.0_9563.eml",
new EmlLoadOptions());
mail1.Save(@"\mail1.eml", EmlSaveOptions.DefaultEml);
MailMessage mail2 = MailMessage.Load(@"5221_a_44_f4115cdda38e5894465eda228dfe8.0_241103.eml",
new EmlLoadOptions());
mail1.Save(@"mail2.eml", EmlSaveOptions.DefaultEml);

Is it possible for you to save the original stream (fetched email from server) in a file and provide us before saving it as EML? This original data stream will help us to observe the problem and provide assistance.


Hi, we save the messageStream to file

using the following code:

				FileOutputStream fos = new FileOutputStream("C:\\temp\\aspose10mb\\imap\\" + fileName + ".ser");
				imapClient.saveMessage(msgId, fos);

resulting file: (7.4 KB)



Thank you for providing the sample data. This issue is reproduced and logged under Id: EMAILJAVA-34299 for further investigation by the product team. You will be automatically notified once any update is received in this regard.



The issue has been fixed. Please download the latest version of Aspose.Email for Java 17.8 for trying it at your end and let us know if you have any further inquiry in this regard.


Thank you.

updating to the newer version did fix this issue.



Thanks for the feedback. It’s good to know that we could be of help to you in resolving this issue. Please feel free to write to us in case of any further query related to the API.