Aspose Java Mail Msg To Eml conversion overrides dates

Hello,

We are converting MSG files to EML files via:

MailMessage message = MailMessage.load(new ByteArrayInputStream(msg), new MsgLoadOptions());
ByteArrayOutputStream out = new ByteArrayOutputStream();
EmlSaveOptions saveOptions = SaveOptions.getDefaultEml();
saveOptions.setPreserveSignedContent(true);
message.save(out, saveOptions);
return out.toByteArray();

The problem is the following:
if the MSG file does NOT have a date (e.g. it’s a draft not ever sent), the EML file will set the current timestamp (smth like LocalDateTime.now()) instead of leaving it blank in the created EML file.

This is actually not wanted. Is there any option to avoid this?

Thanks in advance

@mrossi

When an MSG file does not contain a Date property, Aspose.Email for Java inserts the current system time into the Date header of the generated EML file. The library does not expose a switch to keep that header empty – the conversion routine always writes a timestamp if the source message lacks one [0].

Work‑around

Remove or clear the Date header after loading the MSG and before saving it as EML:

// load the MSG
MailMessage message = MailMessage.load(
        new ByteArrayInputStream(msg), new MsgLoadOptions());

// If the original MSG had no Date, delete the auto‑added header
if (message.getHeaders().containsKey("Date")) {
    message.getHeaders().remove("Date");          // removes the header completely
    // alternatively, if you prefer to keep the property but make it empty:
    // message.setDate(null);
}

// save as EML
ByteArrayOutputStream out = new ByteArrayOutputStream();
EmlSaveOptions saveOptions = SaveOptions.getDefaultEml();
saveOptions.setPreserveSignedContent(true);
message.save(out, saveOptions);
byte[] emlBytes = out.toByteArray();

After the header is removed, the resulting EML file will not contain a Date line, matching the original draft MSG behavior [0].

If you need this behavior globally, you can encapsulate the above logic in a helper method that processes every MSG before conversion. At present there is no dedicated API flag to suppress the automatic timestamp insertion.

Hello @mrossi ,

We have checked your case on our side.

For testing, we created a message in Outlook, saved it as a Unicode MSG file without sending it (i.e. without a Date field). After running the code snippet you provided, we were not able to reproduce the issue.

In the resulting EML file, the Date header is not present. When loading this EML back into MailMessage from a stream, message.getDate() returns the default value Sat Jan 01 00:00:00 EET 1 which indicates that the Date header is missing rather than set to the current timestamp.

Could you please provide the MSG file that demonstrates the issue, if possible, so we can verify it on our side?
Also, please clarify what exactly is being checked during your test (e.g. raw EML headers, message.getDate() value after reload, or behavior in a specific mail client).

image.png (8.6 KB)

image.png (50.7 KB)

Dear Sergey, as you can see in the first image, I get the “no date” for the MSG file, while I get “today” for the converted EML file.

In the second image the code to convert a MSG to an EML.

I am also attaching the MSG input file, since it does not contain any sensible information. (Please, not that it is zipped because this website doesn’t allow me to upload msg files)

Thank you in advance
Mario
mymsg.zip (24.7 KB)

Hello @mrossi ,

Thank you for providing additional information. We’ll investigate your issue and get back soon.

Hello @mrossi ,

Thank you for providing the screenshots and the MSG file.

We have re-checked your case using exactly the same MSG file you attached and code equivalent to the one in your example.

Our findings are the following:

  • After converting MSG → EML, the resulting EML file does NOT contain the Date header.
  • When this EML is loaded back into MailMessage, calling getDate() returns
    Sat Jan 01 00:00:00 EET 1, which is a default placeholder value returned by the API when the Date header is physically missing from the message.
  • The current date (“today”) is not written into the EML file during conversion.

So, technically, the Date field is not set in the EML at all. The “today” value you observe most likely comes from:

  • the way a specific mail client interprets EML files without a Date header, or
  • logic in your test/UI tool that displays the current date when the Date header is missing.

To help us investigate further, could you please clarify:

  1. Which exact tool or mail client you are using to view the EML file (Outlook, Thunderbird, web client, custom parser, etc.)?
  2. Have you checked the raw EML headers, and can you confirm whether a Date: header is present there?
  3. What is the actual issue for you: the presence of the Date header in the EML file itself, or the date value displayed by the UI?

Below is the exact code we used for testing with your provided MSG file:

byte[] msg = File.readAllBytes("test\\mymsg.msg");

// CONVERT MSG -> EML
MailMessage message = MailMessage.load(
        new ByteArrayInputStream(msg),
        new MsgLoadOptions()
);

ByteArrayOutputStream out = new ByteArrayOutputStream();
EmlSaveOptions saveOptions = SaveOptions.getDefaultEml();
saveOptions.setPreserveSignedContent(true);
message.save(out, saveOptions);

// SAVE AND TEST EML
File.writeAllBytes("test\\mymsg.msg.eml", out.toByteArray());

byte[] eml = File.readAllBytes("test\\mymsg.msg.eml");
MailMessage emlMessage = MailMessage.load(
        new ByteArrayInputStream(eml),
        new EmlLoadOptions()
);

System.out.println(emlMessage.getDate()); // out is Sat Jan 01 00:00:00 EET 1

This test consistently shows that the Date header is absent in the generated EML file, and the returned date value is a default one rather than the current timestamp.

By me the problem is present, but I noticed that it is an old version of aspose-mail: 20-10

@mrossi,

Could you please check whether the issue can be reproduced using the latest version of Aspose.Email?

Thank you.

Hello, new version works!

Hello @mrossi,

We appreciate your feedback. Let us know if you have any other questions.

Hello,

Upgrading to 2025-11 introduced another issue: Aspose Email - Sender header with special character is not encoded - #3 by mrossi

Thanks in advance

@mrossi,

ok, sure.