none
Send RichTextBox (RTF Text) contents in Outlook email item

    Question

  • Hi

     

    I am trying to get the contents of a RichTextBox , in a new email item using Outlook 2003

     

    The following code gives me unexpected results !!! , the RTF ecoding is dumped into the email window !

    What I need is to insert the formated text as the body of the email.

     

    using Word = Microsoft.Office.Interop.Word;

    using Outlook = Microsoft.Office.Interop.Outlook;

    // a part of some class

    private void SendEmailUsingOutLook(string rtfBody)

    {

    Outlook.Application outlookApplication =

    new Microsoft.Office.Interop.Outlook.Application();

    Outlook.MailItem email =

    (Outlook.MailItem)outlookApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

    email.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatRichText;

    email.Body = rtfBody;

    email.Display(false);

    }

    private void button2_Click(object sender, EventArgs e)

    {

    SendEmailUsingOutLook(this.RichTextBox1.Rtf);

    }

    Sunday, January 29, 2006 2:35 PM

Answers

  • Actually, according to the code you have, I would expect to see the RTF encoding in the resulting message (for example: {adsfadf\;fcharset0...). Just setting the olBodyFormat property is not enough. You need a way to get the RTF content into the message. You have a few options, the popular of which is using the third party library from Redemption: http://www.outlookcode.com/d/formatmsg.htm

    This will give you what you need.

    John.

    Monday, January 30, 2006 4:14 PM

All replies

  • I have written code in vb .net that uses outlook.taskitem.  I create my body part using my data which is stored in a string. 

    When using outlook 98 the formatting is fine in the body of the task created in the public folder, but when I upgrade to Oulook 2003, the body of the task also shows the formatting i.e. {\rtf1\ansi etc.

    What is the best way to overcome this?
    Thursday, January 26, 2006 4:37 PM
  • Actually, according to the code you have, I would expect to see the RTF encoding in the resulting message (for example: {adsfadf\;fcharset0...). Just setting the olBodyFormat property is not enough. You need a way to get the RTF content into the message. You have a few options, the popular of which is using the third party library from Redemption: http://www.outlookcode.com/d/formatmsg.htm

    This will give you what you need.

    John.

    Monday, January 30, 2006 4:14 PM
  • Is there any way to use the clipboard cut & paste method to accomplish what the initial post was asking?  I too have a RichTextBox that I simply what to get it's contents into the message.body.  If in the code I do a message.display I can manually copy and paste the rich text content into the message body, so couldn't the same thing be done through code?
    Thursday, June 29, 2006 8:49 PM
  • I have been able before to use the Clipboard t odo a similar thing, I had  a word document and need to send its content via email.

     

    I remember doing somthing like that :

    doc.WholeStory.Copy();

    message.paste();

    I am not sure if this will work with RichTextBox or not ....

    richTextBox1.Copy();

    message.paste();

    I will try to find what I did before,then back again to you soon

     

    Saturday, July 01, 2006 11:47 AM
  • Outlook 98 had an undocumented, unsupported feature that allows you to set the Body property to an RTF string. The page that John suggested describes (few) options for handling RTF content in current versions.
    Friday, July 07, 2006 7:11 PM
  • Can you show how TO paste document in the message.body

    e.g

    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
       Set objOutlook = CreateObject("Outlook.Application")   ' Create the message.
       Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

    Dim objApplication As Word.Application
        Dim objWord As Word.Document
        Set objApplication = New Word.Application
        Set objWord = objApplication.Documents.Open("abcDoc.rtf")
        objWord.Select
        objWord.Range.Copy
    With objOutlookMsg
            .To = strMailTo
           .Subject = "Subject"

           .bodyformat=olFormatRichText
           .BODY = objWord.Content <<< Gives me unformatted text

    message.paste() ??????????????? How to write this ??

    Friday, September 08, 2006 3:14 PM