Article ID: 195842 - Last Review: June 6, 2005 - Revision: 3.0

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

This article was previously published under Q195842

On This Page

Expand all | Collapse all

SUMMARY

This article describes how to use Collaboration Data Objects (1.1, 1.2, 1.21) in C++ to change the default reply-recipient of an outgoing message.

MORE INFORMATION

The sample code below demonstrates how to setup two CDO (1.x) 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 {
        // Uncomment one of the next two lines of code as appropriate:
        // Create a MAPI.Session pointer with CDO (1.1)
        // SessionPtr pSession("MAPI.Session");
        // or Create a MAPI.Session pointer with CDO (1.2, 1.21)
        //_SessionPtr pSession("MAPI.Session");

        _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
        // Type can be ActMsgTo, mapiTo or CdoTo for different CDO versions
        // They all have constant value of 1.        
        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);
   
        // Set the two pertinent 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:
181408  (http://support.microsoft.com/kb/181408/EN-US/ ) HOWTO: Use CDO to Set Up Reply to Alternate Recipient

171440  (http://support.microsoft.com/kb/171440/EN-US/ ) INFO: Where to Acquire the Collaboration Data Objects Libraries

174211  (http://support.microsoft.com/kb/174211/EN-US/ ) HOWTO: Access Message Property Not Exposed by Active Messaging

APPLIES TO
  • Microsoft Collaboration Data Objects 1.1
  • Microsoft Collaboration Data Objects 1.2
  • Microsoft Collaboration Data Objects 1.21
Keywords: 
kbfaq kbhowto kbmsg KB195842
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
 

Article Translations