HOWTO: Forwarding Messages Using CDO Version 1.2 (VB Sample)

ID: Q178789

The information in this article applies to:

SUMMARY

The Forward method has been added to the Collaboration Data Objects (CDO) version 1.2 library. When you use the Forward method, it may not perform as desired because the body of the message is not copied to the message to be forwarded. This behavior is by design.

This article contains a Visual Basic code sample showing how to make this work.

MORE INFORMATION

This problem stems from the fact that the Collaboration Data Objects (CDO) library only supports non-RTF (Rich Text Format) by default, but can also be extended to support RTF. This method explicitly leaves the decision up to the developer to determine how a message is to be forwarded.

   'This code sample is dependent upon the CDO version 1.2 library being
   'installed on the target computer.
   '
   Dim objSession As MAPI.Session
   Dim objMsgColl As Messages
   Dim objMsg1 As Message
   Dim objFwdMsg As Message

   Private Sub Form_Load()
   'Create Session and Logon.
   Set objSession = CreateObject("mapi.session")
   objSession.Logon
   Set objMsgColl = objSession.Inbox.Messages
   'First Message.
   Set objMsg1 = objMsgColl.GetFirst
   Set objFwdMsg = objMsg1.Forward
   'BEGIN objFwdMsg BODY CONSTRUCTION
   '
   'For RTF in the body, uncomment the following lines of
   'code. For plain text, uncomment the first line,
   'which is not really required for RTF, except that if you happen
   'to forward the message to a client that cannot read RTF, populating
   'this property allows that client to display the non-RTF
   'variant of the body.
   '
   'objFwdMsg.Text = objMsg1.Text
   'objFwdMsg.Fields.Add CdoPR_RTF_COMPRESSED, _
   'objMsg1.Fields(&H10090102).Value
   '
   'END objFwdMsg BODY CONSTRUCTION
   objFwdMsg.Recipients.Add Name:="YourRecipEmailNameHere"
   objFwdMsg.Recipients.Resolve
      objFwdMsg.Send

      objSession.Logoff
      Set objSession = Nothing
      Unload Me

      End Sub

NOTE: This process of copying the compressed RTF stream to the new message also works for the CDO version 1.1 library. However, version 1.1 of the CDO library does not support the Forward method, so a "Forward" would need to be emulated by copying one field at a time from the fields collection of the original message to the target message.

REFERENCES

For information on where to acquire the most recent version of the CDO library tested for client-side use, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q171440
   TITLE     : INFO: Where to Acquire the Collaboration Data Objects
               Libraries

For additional information about Collaboration Data Objects versus Active Messaging, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q176916
   TITLE     : INFO: Active Messaging and Collaboration Data Objects (CDO)

Additional query words: ActMsg OleMsg
Keywords          : kbcode kbCDO120 kbCDO121 kbMsg kbVBp kbGrpMsg 
Version           : WINDOWS:1.2,1.21
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: April 8, 1999