I faced with issue while
processing appointment message. In case of external recipient Exchange sends
message (through SMTP) with two alternative views: (1) text/plain;; (2) application/ms-tnef;
attached). The problem is when I open message, replace content of attachment
(DOCX-file) using following code:<o:p></o:p>
MailMessage main = MailMessage.Load(@“original_message.eml”);<o:p></o:p>
main.Attachments.ContentStream = new MemoryStream(File.ReadAllBytes("file.docx"));
message comes to recipient (please see attached image):
- in plain text
- stripped of calendar appointment
The same result you can get saving main message to eml-file.
main.Save("saved_Has_no_appointment.eml"); // also attached
The reason of such a behavior (stripping of calendar appointment) is that all information about appointment is contained in TNEF properties of "winmail.dat" and is lost during creating new MailMessage instance.
I tried following code:
MailMessage main = MailMessage.Load(@"original_message.eml",
And recipient will receive message correctly. But it work for me only if message has no attachments. Because if I use ‘PreserveTnefAttachments’ then Attachments collection of ‘main’ message does not contain docx-file, only “winmail.dat” (but I need to have access to docx file to replace content of this attachment).
My question is how I can manipulate attachments without breaking meeting appointments?