We help IT Professionals succeed at work.

Sending html-formatted email with CDO 1.21

GreenFlight
GreenFlight asked
on
Hello,

I'm trying to send html formatted emails using CDO 1.21 library and I'm not having any luck.  Please help!  My email function is a follows:

Function SendMessage(ByVal vTo As Variant, _
                     ByVal sSubject As String, _
                     ByVal sBody As String, _
                     ByRef vntRtnMsg As Variant) As Long
   Const strProc As String = "SendMessage"
   On Error GoTo ProcEH

   Dim mySession As New MAPI.Session
   Dim myMessage As Message
   Dim myRecip As Recipient
   Dim retval As Long
   Dim strTemp As String
   Dim i As Integer

   mySession.Logon _
               nomail:=True, _
               ProfileInfo:=EMAIL_SERVER & vbLf & EMAIL_USER

   Set myMessage = mySession.Outbox.Messages.Add
   Set myObjRend.DataSource = myMessage
   ' create the recipient(s)
   If IsArray(vTo) Then 'if there is more than one recipient, use a loop through the array
      For i = 0 To UBound(vTo)
         Set myRecip = myMessage.Recipients.Add
         myRecip.Name = vTo(i)
         myRecip.Type = CdoTo
         myRecip.Resolve False
      Next i
   Else  'otherwise just add the one recipient
      Set myRecip = myMessage.Recipients.Add
      myRecip.Name = vTo
      myRecip.Type = CdoTo
      myRecip.Resolve False
   End If
   myMessage.Subject = sSubject
   myMessage.Text = sBody
   myMessage.Update
   myMessage.Send

   mySession.Logoff

   SendMessage = 0
ProcExit:
   Set myMessage = Nothing
   Set mySession = Nothing
   Exit Function
ProcEH:
      'Debug.Print Err & "  " & Err.Description
      SendMessage = -1
      tsToolLog.WriteLine "   ERROR: " & Err & " occurred in " & strProc & ".  " & Err.Description
      Resume ProcExit

End Function


And my function call looks like this:

   SendMessage "green_fligh@hotmail.com", "test", "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN""><html><head>This is a test</head><body>" & _
               "This is the first line of the body<p><center><table><tr><td align='right'>Hello</td><td align='left'>" & _
               "This is my table</td></tr><tr><td colspan='2'>Just playing around" & _
               "</td></tr></table></center></body></html>", vntRtnMsg

What can I do to get the exchange server to recognize the email as html??

Thanks in advance,
GF
Comment
Watch Question

You need to specify the format.  By default it's set to plain text.  

Add the following line before you send the message(myMessage.Send):

myMessage.BodyFormat = 0

This specifies the the email format is HTML.  You can have only two values:  
0 = HTML
1 = Text
Richie_SimonettiIT Operations
CERTIFIED EXPERT

Commented:
Interesting...

Author

Commented:
EstebanFG,

I'm not using "CDO 1.2 for NTS library" that has the bodyformat properties;  I'm using "CDO 1.21 Library."

-GF
Oh, I'm sorry, I didn't notice that.
I just found an article that states that CDO 1.21 does not support HTML formatted email.  Here's the link:
http://support.microsoft.com/support/kb/articles/Q177/8/50.ASP

it says that HTML and MHTML support for messages with
   rich text and graphics is only given CDONTS, but not by CDO 1.21

Hope that helps!

Author

Commented:
Oh, well.  Thanks.

-GF

Explore More ContentExplore courses, solutions, and other research materials related to this topic.