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?
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.
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).