Results 1 to 5 of 5

Thread: [RESOLVED] Write RTF to outlook mailitem

  1. #1

    Thread Starter
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    [RESOLVED] Write RTF to outlook mailitem

    I am writing a COM addin for outlook.
    It basically adds a few lines of formatted text to outgoing mailitems (like a signature).
    I am using the ItemSend event of the Outlook application object to trap send messages.
    I have no problems with HTML mail, I just append some html to the HTMLBody property of the mailitem.

    The problem I have is with RTF or Plain text mail.

    When I append the text to the Body property for plain text messages, the mailtype changes to RTF (probably because there is an url and an e-mail address in the text I append).

    When I append the text to the Body property for RTF messages, the formatting of the message is lost. I also don't know how to format the text I need to append (set font information).

    I haven't started with messages in Word format, so I don't know if I encounter problems with these kind of messages.

    Any information is welcome.
    Last edited by Frans C; Feb 7th, 2003 at 10:25 AM.

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    I have no idea if this helps.... but when creating a body of a mail message, in order to make it in RTF format, you need something like this:

    VB Code:
    1. .Body = "{\rtf1\ansi\deff0{\fonttbl{\f0 Arial;}}{\colortbl ;\red0\green0\blue255;}\pard\cf1\f0\fs24 Test}"

  3. #3

    Thread Starter
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Thanks, it helps a bit.

    It seems to work for the text I want to add, but the problem is that the body property doesn't seem to give the RTF contents of the mailitem. If I append RTF to the Body, my added text is not formatted, but displayed as rtf code, and the already existing body lost it's formatting.

    I do something like this:

    item.Body = item.Body & strAdres

    where strAdres is the formatted text (in this case rtf).
    The original formatting is lost, and the added text is not formatted, but displayed as rtf code.

    If I do it like this:

    item.Body = strAdres

    the text is properly formatted, but obvious the original message is gone.

    So i need to find a way to read the original rtf contents of the message, so i can alter it.

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    The help in Outlook says:

    Note: The EditorType property is not affected when you merely access the Body property of the item (as in MsgBox myItem.Body), but when you reset the Body property (as in myItem.Body = "This is a new body"), the EditorType reverts back to the user's default editor.

    Other thoughts:
    .EditorType is ReadOnly.
    There is a .HTMLbody property.
    There is no .RTFbody property.

  5. #5

    Thread Starter
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    I sorted it out.

    It appears the Body property was never intended to accept RTF text, and Microsoft does not support it. This "feature" was introduced by accident, and there is no way of reading the RTF text directly from the mailitem's body property, or another property.
    However, there is a dll available from Microsoft with which it is possible to read the RTF text of the body.
    http://support.microsoft.com/?kbid=172038

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width