Microsoft KB Archive/181408

= HOWTO: Use CDO (1.x) to Set Up Reply to Alternate Recipient =

Article ID: 181408

Article Last Modified on 5/13/2005

-

APPLIES TO


 * Microsoft Collaboration Data Objects 1.1
 * Microsoft Collaboration Data Objects 1.2
 * Microsoft Collaboration Data Objects 1.21

-



This article was previously published under Q181408



SUMMARY
This article describes and gives sample code on how to use Collaboration Data Objects (1.1, 1.2, 1.21) 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".



Sample Code
' The following Visual Basic code sample assumes the a  ' reference has been made to the CDO (1.2x) 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 String

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

' Send the message objMsg.Send End Sub

