HOWTO: Set the Default Reply-Recipient with CDO Using C++

ID: Q195842


The information in this article applies to:
  • Collaboration Data Objects (CDO), versions 1.1, 1.2, 1.21


SUMMARY

This article describes how to use CDO in C++ to change the default reply- recipient of an outgoing message.


MORE INFORMATION

The sample code below demonstrates how to setup two CDO properties:

  • CdoPR_REPLY_RECIPIENT_ENTRIES


  • CdoPR_REPLY_RECIPIENT_NAMES


The sample code also demonstrates how to:
  • Retrieve the first message in the Inbox


  • Create a new message in the Outbox


  • Set the default reply-recipient of the newly-created message to the sender of the first message you retrieved from the Inbox


Sample Code


   #import "cdo.dll" no_namespace
   #include <stdio.h>
   #include <MAPIUTIL.H>
   
   int main(int argc, char* argv[])
   {
     CoInitialize(NULL);
     try {
        _SessionPtr pSession("MAPI.Session");
        pSession->Logon();
        FolderPtr pInbox = pSession->Inbox;
        FolderPtr pOutbox = pSession->Outbox;
   
        // get the first message from the Inbox
        // 
        MessagesPtr pMessages = pInbox->Messages;
        MessagePtr pMessage = pMessages->GetFirst();
   
        // save the sender of this message for the later use
        AddressEntryPtr m_pReply = pMessage->Sender;
   
        // create a new message in the Outbox
        // 
        MessagesPtr pNewMsgs = pOutbox->Messages;
        MessagePtr pNewMsg = pNewMsgs->Add();
   
        // set some properties of the new message
        pNewMsg->Subject = "Set default reply-recipient";
        pNewMsg->Text = "Set up two Cdo properties";
   
        // Create a recipient
        RecipientsPtr pRecipients = pNewMsg->Recipients;
        RecipientPtr pRecipient = pRecipients->Add();
   
        // Set properties of the new recipient
        pRecipient->Name = <your name goes here>; // a string
        pRecipient->Type = (long) mapiTo;
   
        // Resolve the recipient address
        pRecipient->Resolve();
   
        // set the default reply-recipient of pNewMessage to be the
        // Sender of pMessage
        FieldsPtr pFields = pNewMsg->Fields;
   
        // set up a text string that matches the binary signature of the
        // FLATENTRYLIST structure
        char FlatLength[200] = "";
        wsprintf(FlatLength, "%x",
            strlen((char *)(bstr_t)m_pReply->ID)/2 );
        strcat(FlatLength, "000000");
        strcat(FlatLength, (char *)(bstr_t)m_pReply->ID);
   
        char StructLength[200] = "";
        wsprintf(StructLength, "%x", strlen(FlatLength)/2 );
   
        char m_Entry[200] = "";
        strcat(m_Entry, "01000000");
        strcat(m_Entry, StructLength);
        strcat(m_Entry, "000000");
        strcat(m_Entry, FlatLength);
   
        // it is time to set up two properties
        pFields->Add((long)CdoPR_REPLY_RECIPIENT_ENTRIES,
                 (variant_t)m_Entry);
        pFields->Add((long)CdoPR_REPLY_RECIPIENT_NAMES, m_pReply->Name);
   
        // send message with UI
        pNewMsg->Send(true, true);
   
        // or send message without UI
        // pNewMsg->Send(false, false);
   
       } catch (_com_error) {}
   
       CoUninitialize();
   
     return 0;
   } 


REFERENCES

For additional information, please see the following articles in the Microsoft Knowledge Base:

Q181408 HOWTO: Use CDO to Set Up Reply to Alternate Recipient

Q171440 INFO: Where to Acquire the Collaboration Data Objects Libraries

Q176916 INFO: Active Messaging and Collaboration Data Objects (CDO)

Q174211 HOWTO: Access Message Property Not Exposed by Active Messaging

Additional query words:

Keywords : kbole kbCDO110 kbCDO120 kbCDO121 kbMsg kbVC kbfaq kbDSupport
Version : WINDOWS:1.1,1.2,1.21
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: December 3, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.