Article ID: 181408
Article Last Modified on 5/13/2005
' 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
171440 Where to Acquire the Collaboration Data Objects Libraries
174211 HOWTO: Access Message Property Not Exposed by Active Messaging
Additional query words: ReplyTo
Keywords: kbhowto kbmsg kbcode KB181408