I’m trying to append a string to an outgoing Outlook.MailItem. In the send event handler I have:
switch (mailItem.BodyFormat) {
case Outlook.OlBodyFormat.olFormatRichText:
byte[] mailItemBytes = mailItem.RTFBody as byte[];
System.Text.Encoding encoding = new System.Text.ASCIIEncoding();
string RTF = encoding.GetString(mailItemBytes);
RTF += "my string";
byte[] moreMailItemBytes = encoding.GetBytes(RTF);
mailItem.RTFBody = moreMailItemBytes;
break;
// ...
}
but the received email does not contain my string.
RTF is a pretty elaborate format for files and isn’t going to be as easy as concatenating a string. You may try using the RichTextBox control and importing the data there first, adding text to it, then re-grabbing the formatted value back. A bit clunky, but a lot easier than parsing an RTF file.
As an alternative, you may be able to find a library that parses and works with RTF, but that means a dependency for your application and most likely another DLL to include in the release.