HOWTO: Use CDO to Set Up Reply to Alternate Recipient

Last reviewed: February 20, 1998
Article ID: Q181408
The information in this article applies to:
  • Collaboration Data Objects (CDO), versions 1.1, 1.2

SUMMARY

This article describes and gives sample code on how to use 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 user selects "Reply".

MORE INFORMATION

Sample Code

   ' The following Visual Basic code sample assumes the a reference
   ' has been made to the CDO library.
   '
   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 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 BSTR that looks like a FLATENTRYLIST structure.
     FlatLength = CStr(Hex(Len(g_bstrReplyToID) / 2))
     bstrFlatEntry = FlatLength & "000000" & g_bstrReplyToID
     StructLength = Hex(Len(bstrFlatEntry) / 2)
     bstrBlob = "01000000" & StructLength & "000000" & bstrFlatEntry
     objMsg.Fields.Add CdoPR_REPLY_RECIPIENT_NAMES, g_bstrReplyToName
     objMsg.Fields.Add CdoPR_REPLY_RECIPIENT_ENTRIES, bstrBlob

     'Send the Message.
     objMsg.Send

   End Sub

REFERENCES

For additional information, please see the following article(s) in the Microsoft Knowledge Base:

   ARTICLE-ID: Q171440
   TITLE     : Where to Acquire the Active Messaging Libraries

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

   ARTICLE-ID: Q174211
   TITLE     : 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
Keywords : kbcode cdo
Version : WINDOWS:1.1,1.2
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 20, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.