#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;
}