364,112 Members | 2191 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

How do I send RTF formated mail using VB.NET?

John Brock
P: n/a
John Brock
I am currently using a VB.NET program to send out e-mails with
plain text bodies (plus one attachment). The emails are being
received as Rich Text messages (probably just my personal Outlook
default, because I didn't do this in the program), but there is no
actual formatting (italics, color, etc.) in the message body, which
is passed to from VB.NET to Outlook as an unformatted text String.

I want to start applying formatting to the message body. In
particular, my app has a RichTextBox, which has an Rtf property,
which returns a String formatted as RTF, which contains whatever
my users type or paste into the RichTextBox. That is what I want
to send as the body of the message.

Unfortunately all I get is garbage, like this:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\froman\fprq2\fcharset0
Times New Roman;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}
{\colortbl ;\red255\green0\blue0;}
\viewkind4\uc1\pard\f0\fs24 This is \cf1 rich\cf0 \b\i text.\par
\b0\i0\par
\pard\f1\fs17\par
}

This is of course precisely the content of the input String,
formatting and all. Clearly I have failed to clue Outlook in that
the message body should be interpreted as RTF, not plain text. So
how should I do this?

Here is my code:

=== Begin Example ===
Imports Outlook = Microsoft.Office.Interop.Outlook

....

Sub MailerRoutine(ByVal Subject As String, ByVal Recipient As String, _
ByVal Body As String, ByVal Filename As String, ByVal displayName As String)

Dim oApp As Outlook.Application = CreateObject("Outlook.Application")

Dim oItem As Outlook.MailItem = oApp.CreateItem(Outlook.OlItemType.olMailItem)

oItem.Subject = Subject
oItem.To = Recipient
oItem.Body = Body
oItem.BodyFormat = Outlook.OlBodyFormat.olFormatRichText

Dim bodyLength As String = oItem.Body.Length

Dim oAttachments As Outlook.Attachments = oItem.Attachments
Dim oAttachment As Outlook.Attachment
oAttachment = oAttachments.Add(Filename, , bodyLength + 1, displayName)

oItem.Send()

oItem = Nothing
oApp = Nothing
End Sub
=== End Example ===

I got this code from someone else, and I have to admit I don't
really understand how the attachment part work, but that is another
issue. I had thought that adding the line with "olFormatRichText"
would be sufficient to tell Outlook that the message body was RTF,
but clearly it isn't. I'm sure this is really simple, but I just
haven't been able to figure it out, so any help would be appreciated.
--
John Brock
jbrock@panix.com

Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


Sue Mosher [MVP-Outlook]
P: n/a
Sue Mosher [MVP-Outlook]
The Outlook object model itself provides technique for creating an RTF message body. You can set BodyFormat, but that just changes the message format. It doesn't give you a way to actually get the RTF content into the message. To do that, the easiest approach is to use the third-party Redemption library. See http://www.outlookcode.com/d/formatmsg.htm

FYI, the general Outlook programming forum is "down the hall" at microsoft.public.outlook.program_vba
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"John Brock" <jbrock@panix.com> wrote in message news:dhkk65$ebc$1@reader1.panix.com...[color=blue]
>I am currently using a VB.NET program to send out e-mails with
> plain text bodies (plus one attachment). The emails are being
> received as Rich Text messages (probably just my personal Outlook
> default, because I didn't do this in the program), but there is no
> actual formatting (italics, color, etc.) in the message body, which
> is passed to from VB.NET to Outlook as an unformatted text String.
>
> I want to start applying formatting to the message body. In
> particular, my app has a RichTextBox, which has an Rtf property,
> which returns a String formatted as RTF, which contains whatever
> my users type or paste into the RichTextBox. That is what I want
> to send as the body of the message.
>
> Unfortunately all I get is garbage, like this:
>
> {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\froman\fprq2\fcharset0
> Times New Roman;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}
> {\colortbl ;\red255\green0\blue0;}
> \viewkind4\uc1\pard\f0\fs24 This is \cf1 rich\cf0 \b\i text.\par
> \b0\i0\par
> \pard\f1\fs17\par
> }
>
> This is of course precisely the content of the input String,
> formatting and all. Clearly I have failed to clue Outlook in that
> the message body should be interpreted as RTF, not plain text. So
> how should I do this?
>
> Here is my code:
>
> === Begin Example ===
> Imports Outlook = Microsoft.Office.Interop.Outlook
>
> ...
>
> Sub MailerRoutine(ByVal Subject As String, ByVal Recipient As String, _
> ByVal Body As String, ByVal Filename As String, ByVal displayName As String)
>
> Dim oApp As Outlook.Application = CreateObject("Outlook.Application")
>
> Dim oItem As Outlook.MailItem = oApp.CreateItem(Outlook.OlItemType.olMailItem)
>
> oItem.Subject = Subject
> oItem.To = Recipient
> oItem.Body = Body
> oItem.BodyFormat = Outlook.OlBodyFormat.olFormatRichText
>
> Dim bodyLength As String = oItem.Body.Length
>
> Dim oAttachments As Outlook.Attachments = oItem.Attachments
> Dim oAttachment As Outlook.Attachment
> oAttachment = oAttachments.Add(Filename, , bodyLength + 1, displayName)
>
> oItem.Send()
>
> oItem = Nothing
> oApp = Nothing
> End Sub
> === End Example ===
>
> I got this code from someone else, and I have to admit I don't
> really understand how the attachment part work, but that is another
> issue. I had thought that adding the line with "olFormatRichText"
> would be sufficient to tell Outlook that the message body was RTF,
> but clearly it isn't. I'm sure this is really simple, but I just
> haven't been able to figure it out, so any help would be appreciated.
> --
> John Brock
> jbrock@panix.com
>[/color]
Nov 21 '05 #2

Mr Newbie
P: n/a
Mr Newbie
And who said newsgroups should not be used to promote one's business ?

:-)


"Sue Mosher [MVP-Outlook]" <suemvp@outlookcode.com> wrote in message
news:%23wAuMglxFHA.2960@tk2msftngp13.phx.gbl...
The Outlook object model itself provides technique for creating an RTF
message body. You can set BodyFormat, but that just changes the message
format. It doesn't give you a way to actually get the RTF content into the
message. To do that, the easiest approach is to use the third-party
Redemption library. See http://www.outlookcode.com/d/formatmsg.htm

FYI, the general Outlook programming forum is "down the hall" at
microsoft.public.outlook.program_vba
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"John Brock" <jbrock@panix.com> wrote in message
news:dhkk65$ebc$1@reader1.panix.com...[color=blue]
>I am currently using a VB.NET program to send out e-mails with
> plain text bodies (plus one attachment). The emails are being
> received as Rich Text messages (probably just my personal Outlook
> default, because I didn't do this in the program), but there is no
> actual formatting (italics, color, etc.) in the message body, which
> is passed to from VB.NET to Outlook as an unformatted text String.
>
> I want to start applying formatting to the message body. In
> particular, my app has a RichTextBox, which has an Rtf property,
> which returns a String formatted as RTF, which contains whatever
> my users type or paste into the RichTextBox. That is what I want
> to send as the body of the message.
>
> Unfortunately all I get is garbage, like this:
>
> {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\froman\fprq2\fcharset0
> Times New Roman;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}
> {\colortbl ;\red255\green0\blue0;}
> \viewkind4\uc1\pard\f0\fs24 This is \cf1 rich\cf0 \b\i text.\par
> \b0\i0\par
> \pard\f1\fs17\par
> }
>
> This is of course precisely the content of the input String,
> formatting and all. Clearly I have failed to clue Outlook in that
> the message body should be interpreted as RTF, not plain text. So
> how should I do this?
>
> Here is my code:
>
> === Begin Example ===
> Imports Outlook = Microsoft.Office.Interop.Outlook
>
> ...
>
> Sub MailerRoutine(ByVal Subject As String, ByVal Recipient As String, _
> ByVal Body As String, ByVal Filename As String, ByVal displayName As
> String)
>
> Dim oApp As Outlook.Application = CreateObject("Outlook.Application")
>
> Dim oItem As Outlook.MailItem =
> oApp.CreateItem(Outlook.OlItemType.olMailItem)
>
> oItem.Subject = Subject
> oItem.To = Recipient
> oItem.Body = Body
> oItem.BodyFormat = Outlook.OlBodyFormat.olFormatRichText
>
> Dim bodyLength As String = oItem.Body.Length
>
> Dim oAttachments As Outlook.Attachments = oItem.Attachments
> Dim oAttachment As Outlook.Attachment
> oAttachment = oAttachments.Add(Filename, , bodyLength + 1, displayName)
>
> oItem.Send()
>
> oItem = Nothing
> oApp = Nothing
> End Sub
> === End Example ===
>
> I got this code from someone else, and I have to admit I don't
> really understand how the attachment part work, but that is another
> issue. I had thought that adding the line with "olFormatRichText"
> would be sufficient to tell Outlook that the message body was RTF,
> but clearly it isn't. I'm sure this is really simple, but I just
> haven't been able to figure it out, so any help would be appreciated.
> --
> John Brock
> jbrock@panix.com
>[/color]


Nov 21 '05 #3

John Brock
P: n/a
John Brock
In article <#wAuMglxFHA.2960@tk2msftngp13.phx.gbl>,
Sue Mosher [MVP-Outlook] <suemvp@outlookcode.com> wrote:[color=blue]
>The Outlook object model itself provides technique for creating an RTF message body. You can
>set BodyFormat, but that just changes the message format. It doesn't give you a way to
>actually get the RTF content into the message. To do that, the easiest approach is to use
>the third-party Redemption library. See http://www.outlookcode.com/d/formatmsg.htm[/color]

I need this tomorrow, and I am afraid that third-party solutions
are out of the question in any case. Since I already have an RTF
formatted text string, are you saying there is no straightforward
way to insert it into an Outlook message? I would have assumed
that Microsoft would make this easy, since it seems like such a
natural thing to want to do, but then you never know with MS.
[color=blue]
>FYI, the general Outlook programming forum is "down the hall" at
>microsoft.public.outlook.program_vba[/color]

Thanks, I'll give it a shot.
[color=blue]
>"John Brock" <jbrock@panix.com> wrote in message news:dhkk65$ebc$1@reader1.panix.com...[color=green]
>>I am currently using a VB.NET program to send out e-mails with
>> plain text bodies (plus one attachment). The emails are being
>> received as Rich Text messages (probably just my personal Outlook
>> default, because I didn't do this in the program), but there is no
>> actual formatting (italics, color, etc.) in the message body, which
>> is passed to from VB.NET to Outlook as an unformatted text String.
>>
>> I want to start applying formatting to the message body. In
>> particular, my app has a RichTextBox, which has an Rtf property,
>> which returns a String formatted as RTF, which contains whatever
>> my users type or paste into the RichTextBox. That is what I want
>> to send as the body of the message.
>>
>> Unfortunately all I get is garbage, like this:
>>
>> {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\froman\fprq2\fcharset0
>> Times New Roman;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}
>> {\colortbl ;\red255\green0\blue0;}
>> \viewkind4\uc1\pard\f0\fs24 This is \cf1 rich\cf0 \b\i text.\par
>> \b0\i0\par
>> \pard\f1\fs17\par
>> }
>>
>> This is of course precisely the content of the input String,
>> formatting and all. Clearly I have failed to clue Outlook in that
>> the message body should be interpreted as RTF, not plain text. So
>> how should I do this?
>>
>> Here is my code:
>>
>> === Begin Example ===
>> Imports Outlook = Microsoft.Office.Interop.Outlook
>>
>> ...
>>
>> Sub MailerRoutine(ByVal Subject As String, ByVal Recipient As String, _
>> ByVal Body As String, ByVal Filename As String, ByVal displayName As String)
>>
>> Dim oApp As Outlook.Application = CreateObject("Outlook.Application")
>>
>> Dim oItem As Outlook.MailItem = oApp.CreateItem(Outlook.OlItemType.olMailItem)
>>
>> oItem.Subject = Subject
>> oItem.To = Recipient
>> oItem.Body = Body
>> oItem.BodyFormat = Outlook.OlBodyFormat.olFormatRichText
>>
>> Dim bodyLength As String = oItem.Body.Length
>>
>> Dim oAttachments As Outlook.Attachments = oItem.Attachments
>> Dim oAttachment As Outlook.Attachment
>> oAttachment = oAttachments.Add(Filename, , bodyLength + 1, displayName)
>>
>> oItem.Send()
>>
>> oItem = Nothing
>> oApp = Nothing
>> End Sub
>> === End Example ===
>>
>> I got this code from someone else, and I have to admit I don't
>> really understand how the attachment part work, but that is another
>> issue. I had thought that adding the line with "olFormatRichText"
>> would be sufficient to tell Outlook that the message body was RTF,
>> but clearly it isn't. I'm sure this is really simple, but I just
>> haven't been able to figure it out, so any help would be appreciated.
>> --
>> John Brock
>> jbrock@panix.com
>>[/color][/color]


--
John Brock
jbrock@panix.com

Nov 21 '05 #4

John Brock
P: n/a
John Brock
[Note: microsoft.public.outlook.program_vba was suggested as a good
forum for this question when I posted it elsewhere, but for some
reason my ISP doesn't carry that newgroup, and won't let me post
there, except as part of a cross-post, so my apologies to anyone
who sees this twice.]

I am currently using a VB.NET program to send out e-mails with
plain text bodies (plus one attachment). The emails are being
received as Rich Text messages (probably just my personal Outlook
default, because I didn't do this in the program), but there is no
actual formatting (italics, color, etc.) in the message body, which
is passed to from VB.NET to Outlook as an unformatted text String.

I want to start applying formatting to the message body. In
particular, my app has a RichTextBox, which has an Rtf property,
which returns a String formatted as RTF, which contains whatever
my users type or paste into the RichTextBox. That is what I want
to send as the body of the message.

Unfortunately all I get is garbage, like this:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\froman\fprq2\fcharset0
Times New Roman;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}
{\colortbl ;\red255\green0\blue0;}
\viewkind4\uc1\pard\f0\fs24 This is \cf1 rich\cf0 \b\i text.\par
\b0\i0\par
\pard\f1\fs17\par
}

This is of course precisely the content of the input String,
formatting and all. Clearly I have failed to clue Outlook in that
the message body should be interpreted as RTF, not plain text. So
how should I do this?

Here is my code:

=== Begin Example ===
Imports Outlook = Microsoft.Office.Interop.Outlook

....

Sub MailerRoutine(ByVal Subject As String, ByVal Recipient As String, _
ByVal Body As String, ByVal Filename As String, ByVal displayName As String)

Dim oApp As Outlook.Application = CreateObject("Outlook.Application")

Dim oItem As Outlook.MailItem = oApp.CreateItem(Outlook.OlItemType.olMailItem)

oItem.Subject = Subject
oItem.To = Recipient
oItem.Body = Body
oItem.BodyFormat = Outlook.OlBodyFormat.olFormatRichText

Dim bodyLength As String = oItem.Body.Length

Dim oAttachments As Outlook.Attachments = oItem.Attachments
Dim oAttachment As Outlook.Attachment
oAttachment = oAttachments.Add(Filename, , bodyLength + 1, displayName)

oItem.Send()

oItem = Nothing
oApp = Nothing
End Sub
=== End Example ===

I got this code from someone else, and I have to admit I don't
really understand how the attachment part work, but that is another
issue. I had thought that adding the line with "olFormatRichText"
would be sufficient to tell Outlook that the message body was RTF,
but clearly it isn't. I'm sure this is really simple, but I just
haven't been able to figure it out, so any help would be appreciated.
--
John Brock
jbrock@panix.com

Nov 21 '05 #5

Sue Mosher [MVP-Outlook]
P: n/a
Sue Mosher [MVP-Outlook]
Yes, that's exactly what I'm saying. The page I suggested describes your choices:

1) Redemption (easy, but third party)

2) CDO 1.21 and another helper .dll (CDO not being officially. supported in .NET languages, although I've heard of people using it)

3) If Word is the email editor, save the .rtf as a file, then open that file and copy paste text using Word objects. (Outlook exposes the Document for an email message through Inspector.WordEditor.)

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"John Brock" <jbrock@panix.com> wrote in message news:dhp6l4$ga3$1@reader1.panix.com...[color=blue]
> In article <#wAuMglxFHA.2960@tk2msftngp13.phx.gbl>,
> Sue Mosher [MVP-Outlook] <suemvp@outlookcode.com> wrote:[color=green]
>>The Outlook object model itself provides technique for creating an RTF message body. You can
>>set BodyFormat, but that just changes the message format. It doesn't give you a way to
>>actually get the RTF content into the message. To do that, the easiest approach is to use
>>the third-party Redemption library. See http://www.outlookcode.com/d/formatmsg.htm [/color]
>
> I need this tomorrow, and I am afraid that third-party solutions
> are out of the question in any case. Since I already have an RTF
> formatted text string, are you saying there is no straightforward
> way to insert it into an Outlook message? I would have assumed
> that Microsoft would make this easy, since it seems like such a
> natural thing to want to do, but then you never know with MS.
> [color=green]
>>"John Brock" <jbrock@panix.com> wrote in message news:dhkk65$ebc$1@reader1.panix.com...[color=darkred]
>>>I am currently using a VB.NET program to send out e-mails with
>>> plain text bodies (plus one attachment). The emails are being
>>> received as Rich Text messages (probably just my personal Outlook
>>> default, because I didn't do this in the program), but there is no
>>> actual formatting (italics, color, etc.) in the message body, which
>>> is passed to from VB.NET to Outlook as an unformatted text String.
>>>
>>> I want to start applying formatting to the message body. In
>>> particular, my app has a RichTextBox, which has an Rtf property,
>>> which returns a String formatted as RTF, which contains whatever
>>> my users type or paste into the RichTextBox. That is what I want
>>> to send as the body of the message.
>>>
>>> Unfortunately all I get is garbage, like this:
>>>
>>> {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\froman\fprq2\fcharset0
>>> Times New Roman;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}
>>> {\colortbl ;\red255\green0\blue0;}
>>> \viewkind4\uc1\pard\f0\fs24 This is \cf1 rich\cf0 \b\i text.\par
>>> \b0\i0\par
>>> \pard\f1\fs17\par
>>> }
>>>
>>> This is of course precisely the content of the input String,
>>> formatting and all. Clearly I have failed to clue Outlook in that
>>> the message body should be interpreted as RTF, not plain text. So
>>> how should I do this?
>>>
>>> Here is my code:
>>>
>>> === Begin Example ===
>>> Imports Outlook = Microsoft.Office.Interop.Outlook
>>>
>>> ...
>>>
>>> Sub MailerRoutine(ByVal Subject As String, ByVal Recipient As String, _
>>> ByVal Body As String, ByVal Filename As String, ByVal displayName As String)
>>>
>>> Dim oApp As Outlook.Application = CreateObject("Outlook.Application")
>>>
>>> Dim oItem As Outlook.MailItem = oApp.CreateItem(Outlook.OlItemType.olMailItem)
>>>
>>> oItem.Subject = Subject
>>> oItem.To = Recipient
>>> oItem.Body = Body
>>> oItem.BodyFormat = Outlook.OlBodyFormat.olFormatRichText
>>>
>>> Dim bodyLength As String = oItem.Body.Length
>>>
>>> Dim oAttachments As Outlook.Attachments = oItem.Attachments
>>> Dim oAttachment As Outlook.Attachment
>>> oAttachment = oAttachments.Add(Filename, , bodyLength + 1, displayName)
>>>
>>> oItem.Send()
>>>
>>> oItem = Nothing
>>> oApp = Nothing
>>> End Sub
>>> === End Example ===
>>>
>>> I got this code from someone else, and I have to admit I don't
>>> really understand how the attachment part work, but that is another
>>> issue. I had thought that adding the line with "olFormatRichText"
>>> would be sufficient to tell Outlook that the message body was RTF,
>>> but clearly it isn't. I'm sure this is really simple, but I just
>>> haven't been able to figure it out, so any help would be appreciated.
>>> --
>>> John Brock
>>> jbrock@panix.com
>>>[/color][/color]
>
>
> --
> John Brock
> jbrock@panix.com
>[/color]
Nov 21 '05 #6

RgSystems
P: n/a
RgSystems
hi,


did you find any solution to your problem ?

I have the same problem with Word object automation.

Thanks in avance.

Roberto Garcia Martín

"John Brock" <jbrock@panix.com> escribió en el mensaje
news:dhkk65$ebc$1@reader1.panix.com...[color=blue]
>I am currently using a VB.NET program to send out e-mails with
> plain text bodies (plus one attachment). The emails are being
> received as Rich Text messages (probably just my personal Outlook
> default, because I didn't do this in the program), but there is no
> actual formatting (italics, color, etc.) in the message body, which
> is passed to from VB.NET to Outlook as an unformatted text String.
>
> I want to start applying formatting to the message body. In
> particular, my app has a RichTextBox, which has an Rtf property,
> which returns a String formatted as RTF, which contains whatever
> my users type or paste into the RichTextBox. That is what I want
> to send as the body of the message.
>
> Unfortunately all I get is garbage, like this:
>
> {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\froman\fprq2\fcharset0
> Times New Roman;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}
> {\colortbl ;\red255\green0\blue0;}
> \viewkind4\uc1\pard\f0\fs24 This is \cf1 rich\cf0 \b\i text.\par
> \b0\i0\par
> \pard\f1\fs17\par
> }
>
> This is of course precisely the content of the input String,
> formatting and all. Clearly I have failed to clue Outlook in that
> the message body should be interpreted as RTF, not plain text. So
> how should I do this?
>
> Here is my code:
>
> === Begin Example ===
> Imports Outlook = Microsoft.Office.Interop.Outlook
>
> ...
>
> Sub MailerRoutine(ByVal Subject As String, ByVal Recipient As String, _
> ByVal Body As String, ByVal Filename As String, ByVal displayName As
> String)
>
> Dim oApp As Outlook.Application = CreateObject("Outlook.Application")
>
> Dim oItem As Outlook.MailItem =
> oApp.CreateItem(Outlook.OlItemType.olMailItem)
>
> oItem.Subject = Subject
> oItem.To = Recipient
> oItem.Body = Body
> oItem.BodyFormat = Outlook.OlBodyFormat.olFormatRichText
>
> Dim bodyLength As String = oItem.Body.Length
>
> Dim oAttachments As Outlook.Attachments = oItem.Attachments
> Dim oAttachment As Outlook.Attachment
> oAttachment = oAttachments.Add(Filename, , bodyLength + 1, displayName)
>
> oItem.Send()
>
> oItem = Nothing
> oApp = Nothing
> End Sub
> === End Example ===
>
> I got this code from someone else, and I have to admit I don't
> really understand how the attachment part work, but that is another
> issue. I had thought that adding the line with "olFormatRichText"
> would be sufficient to tell Outlook that the message body was RTF,
> but clearly it isn't. I'm sure this is really simple, but I just
> haven't been able to figure it out, so any help would be appreciated.
> --
> John Brock
> jbrock@panix.com
>[/color]


Nov 21 '05 #7

Sue Mosher [MVP-Outlook]
P: n/a
Sue Mosher [MVP-Outlook]
Roberto, I'd suggest that you describe your problem from scratch. It may not be the same as John's. Bottom line is that Outlook itself has no direct way to create RTF formatted messages. See http://www.outlookcode.com/d/formatmsg.htm
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"RgSystems" <rgsystems@telefonica.net> wrote in message news:uYSA5vkyFHA.1032@TK2MSFTNGP12.phx.gbl...[color=blue]
> hi,
>
>
> did you find any solution to your problem ?
>
> I have the same problem with Word object automation.
>
> Thanks in avance.
>
> Roberto Garcia Martín
>
> "John Brock" <jbrock@panix.com> escribió en el mensaje
> news:dhkk65$ebc$1@reader1.panix.com...[color=green]
>>I am currently using a VB.NET program to send out e-mails with
>> plain text bodies (plus one attachment). The emails are being
>> received as Rich Text messages (probably just my personal Outlook
>> default, because I didn't do this in the program), but there is no
>> actual formatting (italics, color, etc.) in the message body, which
>> is passed to from VB.NET to Outlook as an unformatted text String.
>>
>> I want to start applying formatting to the message body. In
>> particular, my app has a RichTextBox, which has an Rtf property,
>> which returns a String formatted as RTF, which contains whatever
>> my users type or paste into the RichTextBox. That is what I want
>> to send as the body of the message.
>>
>> Unfortunately all I get is garbage, like this:
>>
>> {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\froman\fprq2\fcharset0
>> Times New Roman;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}
>> {\colortbl ;\red255\green0\blue0;}
>> \viewkind4\uc1\pard\f0\fs24 This is \cf1 rich\cf0 \b\i text.\par
>> \b0\i0\par
>> \pard\f1\fs17\par
>> }
>>
>> This is of course precisely the content of the input String,
>> formatting and all. Clearly I have failed to clue Outlook in that
>> the message body should be interpreted as RTF, not plain text. So
>> how should I do this?
>>
>> Here is my code:
>>
>> === Begin Example ===
>> Imports Outlook = Microsoft.Office.Interop.Outlook
>>
>> ...
>>
>> Sub MailerRoutine(ByVal Subject As String, ByVal Recipient As String, _
>> ByVal Body As String, ByVal Filename As String, ByVal displayName As
>> String)
>>
>> Dim oApp As Outlook.Application = CreateObject("Outlook.Application")
>>
>> Dim oItem As Outlook.MailItem =
>> oApp.CreateItem(Outlook.OlItemType.olMailItem)
>>
>> oItem.Subject = Subject
>> oItem.To = Recipient
>> oItem.Body = Body
>> oItem.BodyFormat = Outlook.OlBodyFormat.olFormatRichText
>>
>> Dim bodyLength As String = oItem.Body.Length
>>
>> Dim oAttachments As Outlook.Attachments = oItem.Attachments
>> Dim oAttachment As Outlook.Attachment
>> oAttachment = oAttachments.Add(Filename, , bodyLength + 1, displayName)
>>
>> oItem.Send()
>>
>> oItem = Nothing
>> oApp = Nothing
>> End Sub
>> === End Example ===
>>
>> I got this code from someone else, and I have to admit I don't
>> really understand how the attachment part work, but that is another
>> issue. I had thought that adding the line with "olFormatRichText"
>> would be sufficient to tell Outlook that the message body was RTF,
>> but clearly it isn't. I'm sure this is really simple, but I just
>> haven't been able to figure it out, so any help would be appreciated.
>> --
>> John Brock
>> jbrock@panix.com
>> [/color]
>
>[/color]
Nov 21 '05 #8

RgSystems
P: n/a
RgSystems
hi Sue,

all right, thak you very much for your answer.
I've put one message in at the top of this newsgroup.

Ref. "oRange.text = ?? "

thanks a lot.
Roberto Garcia Martin


Nov 21 '05 #9

Post your reply

Help answer this question



Didn't find the answer to your Visual Basic .NET question?

You can also browse similar questions: Visual Basic .NET