3

Following Ries Vriend's answer in regards to loading CDO.Message from EML file, I'm trying to modify the message's body and attachments and save it back to a file (while keeping the original format of the file).

I wrote the following, which doesn't work - the message is written to the file, but the message is not modified and the charset is different from the original message:

 CDO.Message msg = new CDO.MessageClass();
 //load message from EML file
 //....

 //try to modify the body of the message
 message.TextBody = "Modified body";   

 ADODB.Stream stream = new ADODB.StreamClass();
 stream.Open();
 stream.Type = message.GetStream().Type;
 stream.Charset = message.GetStream().Charset;

 message.DataSource.SaveToObject(stream, "_Stream");
 stream.SaveToFile("modified.eml", ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
Community
  • 1
  • 1
elad-ep
  • 333
  • 1
  • 9
  • Did you solve this issue? If you did it would be great if you could post your solution as an answer, especially because this is one of the top results when googling for "create eml-File from CDO.Message" – Breeze Sep 09 '16 at 06:53
  • update: the code seems to work (thank you, that already helped me), but changing the `TextBody` does not seem to affect the `HTMLBody`, was that the problem? – Breeze Sep 09 '16 at 07:22

0 Answers0