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

ID: Q195842

The information in this article applies to:

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:

The sample code also demonstrates how to:

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:

   ARTICLE-ID: Q181408
   TITLE     : HOWTO: Use CDO to Set Up Reply to Alternate Recipient

   ARTICLE-ID: Q171440
   TITLE     : INFO: Where to Acquire the Collaboration Data Objects
               Libraries

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

   ARTICLE-ID: Q174211

   TITLE     : HOWTO: Access Message Property Not Exposed by Active
               Messaging

Additional query words:
Keywords          : kbole kbCDO110 kbCDO120 kbCDO121 kbMsg kbVC 
Version           : WINDOWS:1.1,1.2,1.21
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: April 7, 1999