Hi.
Scenario: I have EML message in TNEF format (it contains winmail.dat MIME part) - “original.eml”. EML message contains embedded message. My code replaces existing embedded messages with the one from file (“cleaned-embedded.eml”) and saves main EML message back to file.
Issue: Re-saved EML message (“main.updated.eml”) still has old embedded message - see attachments of the embedded message.
Code
var originalPath = @"main.original.eml";
var originalUpdatedPath = @"main.updated.eml";
var cleanedEmbeddedMessagePath = @"cleaned-embedded.eml";
using (var originalStream = File.OpenRead(originalPath))
using (var originalMessageCopy = MailMessage.Load(originalStream, new EmlLoadOptions
{
PreserveEmbeddedMessageFormat = true,
PreserveTnefAttachments = false,
}))
using (var cleanedEmbeddedMessageStream = File.OpenRead(cleanedEmbeddedMessagePath))
{
var att = originalMessageCopy.Attachments[0];
att.ContentStream = cleanedEmbeddedMessageStream;
att.Name = "cleaned embedded message";
var saveOptions = SaveOptions.DefaultEml;
saveOptions.FileCompatibilityMode = FileCompatibilityMode.PreserveTnefAttachments;
saveOptions.PreserveEmbeddedMessageFormat = true;
originalMessageCopy.Save(originalUpdatedPath, saveOptions);
}
sample.zip (6.5 MB)
Thanks.
For internal reference: MDP-12534