+1 vote
by (140 points)

I need to compose e-mail and I have rtf-formatted text (inserted by user in our application). What I have to do to create and send Rebex.Mail.MailMessage? I read the news "Secure Mail" component contained Rtf-to-Html converter (for loading outlook messages), but I can't find any class/method/property I should use...

Applies to: Rebex Secure Mail

1 Answer

+1 vote
by (58.9k points)

You can feed the RTF text into the MailMessage class via Attachments collection like this:

byte[] rtf; // source RTF text as array of bytes

MailMessage mail = new MailMessage();

Attachment att = new Attachment();
att.Options = Rebex.Mime.MimeOptions.AllowAnyTextCharacters;

att.SetContent(new MemoryStream(rtf), "file.rtf", "application/rtf");

then you would have to save and reload the mail to raise Rtf to Html conversion like this:

MemoryStream ms = new MemoryStream();
ms.Position = 0;

finally you can find the converted HTML in BodyHtml property (mail.BodyHtml), so if you send the email now, it will contain the HTML version of the original RTF document you supplied which will make it possible to read the mail by most email clients.