Edit Msg

Hello
A Msg file has 2 body parts, Rtf and Html, no Text part, I load it to MapiMessage, SetBodyContent twice, first for its Html part, second for its Rtf part, and then save it, saved Msg will also have Text part, I didn’t set or modify the Text part, how to prevent it? Thanks.

You already declared that MapiMessage.SetBodyContent sets all properties, however, to set the Html part, no other method is provided as .BodyHtml is read-only!

If I only use .SetBodyRtf just once to update the Rtf part, Html part is also updated, seems that it’s generated from Rtf somehow, the problem: a Text part is also added to the target Msg!

Even using .BodyRtf only won’t help as it force make a Text part!

@australian.dev.nerds,

There should always be a text part, that’s normal. However, just remove the PidTagBody property if you want.

1 Like

Thanks, because before this edit, there were no text part, so shouldn’t there be a Rtf body part SET method that only update Rtf part? And does not alter other parts, means if Text part exists, keep it, otherwise, don’t add it.

Thanks for the tip, how to remove PidTagBody?

Finally, I load the MapiMessage.BodyRtf into Aspose Words Document, set a color for Document:
Document.PageColor = Color.Red
Then load the new Rtf back to MapiMessage.
Now, when I save MapiMessage the back color is not applied.

I saved and compared original MapiMessage.BodyRtf vs Words saved Rtf:
Rtf.zip (125.7 KB)

Size is ~7 times bigger when saved using Words and very different, which Rtf version is used for Outlook Rtf?

Thanks :slight_smile:

Sorry, if there’s a method to access and update the backcolor property of MapiMessage (via RtfBody) kindly let me know :slight_smile:

That’s how SetBodyContent works.

msg.Properties.Remove(KnownPropertyList.Body);

I didn’t see the problem:

var content = File.ReadAllText(Path.Combine(dir, "2.rtf"));
msg.SetBodyContent(content, BodyContentType.Rtf);
msg.Save(@"updated.msg");

The difference is that Outlook may use both extended RTF and classic RTF.

In your case, 1.rtf is in the extended version and 2.rtf is in the classic version.

body background processing is a task beyond the capabilities of our email API