HOWTO: Use CDO to Set Up Reply to Alternate Recipient

ID: Q181408


The information in this article applies to:


SUMMARY

This article describes and gives sample code on how to use Collaboration Data Objects (CDO) to set an alternate "Reply To" recipient of a message. This functionality, when enabled on a message, automatically populates the Recipients collection of the message with a recipient other than the original sender (which is the default) when the recipient of this message selects 'Reply'.


MORE INFORMATION

Sample Code


   ' The following Visual Basic code sample assumes the a
   ' reference has been made to the CDO library. If you are
   ' using CDO version 1.1, preface the constants used below with
   ' "ActMsg" instead of "Cdo".
   '
   ' Example - Change CdoPR_REPLY_RECIPIENT_NAMES to
   '                  ActMsgPR_REPLY_RECIPIENT_NAMES
   '

   Option Explicit
   Dim objSession As MAPI.Session
   Dim objMsg As Message
   Dim objAltRecip As Recipient
   Dim g_bstrReplyToID As Variant
   Dim g_bstrReplyToName As String
   Dim FlatLength As String
   Dim StructLength As Integer

   Dim bstrFlatEntry As Variant
   Dim bstrBlob As Variant

   Private Sub Form_Load()
     Set objSession = CreateObject("MAPI.Session")
     objSession.Logon "My Profile Name"

     'Create Message and add a Recipient.
     Set objMsg = objSession.Outbox.Messages.Add( _
                   Subject:="This is the subject line", _
                   Text:="This is the body of the message")

     objMsg.Recipients.Add Name:="NameOfMyMsgRecipient"
     objMsg.Recipients.Resolve

     'Enable the Alternate Recipient functionality
     '--------------------------------------------
     ' 1. Get an AddrEntry for the Alternate Recipient.
     Set objAltRecip = objMsg.Recipients.Add(Name:="NameOfMyMsgAltRecip")
     objAltRecip.Resolve

     ' 2. Assign the ID and Name to variables for subsequent use.
     g_bstrReplyToID = objAltRecip.ID
     g_bstrReplyToName = objAltRecip.Name

     ' 3. Remove the Alternate Recipient from the Recipient list (if
     '    applicable).
     objAltRecip.Delete

     ' 4. Hash the ID into a BSTR that looks like a FLATENTRYLIST structure
     ' Calculate the length of a string converted Hex representation of the
     ' alt recips EntryID.
     ' Divide this value by to to calculate how long this will appear to
     ' MAPI when it views it as a numeric value rather than as a string (or
     ' more appropriately char.)
     FlatLength = CStr(Hex(Len(g_bstrReplyToID) / 2))

     ' Concatenate members of the FLATENTRY stucture: A) Length of entire
     ' FLATENTRY
     ' structure, B) Padding, C) ENTRYID of Alt Recip
     bstrFlatEntry = FlatLength & "000000" & g_bstrReplyToID

     ' Now calculate the length of the entire FLATENTRY structure as a
     ' string and again divide by 2 to determine length when viewed as a
     ' numeric value.
     StructLength = Hex(Len(bstrFlatEntry) / 2)

     ' Assemble the components of the FLATENTRYLIST structure: A)
     ' "01000000" ' defines how many FLATENTRY structures there are in
     ' the FLATENTRYLIST (plus padding) -
     ' There is only 1 in this sample, B) the length of the first (and
     ' only) FLATENTRY array member, C) more padding, D) the EntryID of the
     ' Alt Recip (as a string)
     bstrBlob = "01000000" & StructLength & "000000" & bstrFlatEntry

     ' Write the values to the fields
     objMsg.Fields.Add CdoPR_REPLY_RECIPIENT_NAMES, g_bstrReplyToName
     objMsg.Fields.Add CdoPR_REPLY_RECIPIENT_ENTRIES, bstrBlob 


REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

Q171440 Where to Acquire the Collaboration Data Objects Libraries
Q176916 INFO: Active Messaging and Collaboration Data Objects
Q174211 HOWTO: Access Message Property Not Exposed by Active Messaging
For additional information on the FLATENTRYLIST structure or "Collaboration Data Objects," please see the Microsoft Developer Network (MSDN) Library.

Additional query words: ActMsg ReplyTo


Keywords          : kbcode kbCDO110 kbCDO120 kbCDO121 kbMsg kbVBp kbGrpMsg 
Version           : WINDOWS:1.1,1.2,1.21
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: August 3, 1999