Replying to Messages

Topic Last Modified: 2006-06-12

You can easily reply to a message using the IMessage.Reply or IMessage.ReplyAll methods. These methods mimic the behavior of e-mail programs such as Microsoft® Outlook®.

Both methods return a new Message object reference. The difference in the two methods is that the ReplyAll method retains the original message's CC line in the new message. You must set the From property in the new message before you send the message.

If the https://schemas.microsoft.com/cdo/configuration/usemessageresponsetext field is set to True (VARIANT_TRUE), the TextBody of the reply method contains standard reply formatting. For example,

----Original Message----
From: "A Person" <person@example.com>
Sent:  Sat, 23 Jan 1998 12:34:34 -0800
To:  "Another" <another@example.com>
Subject: See this attached message

(body of the message here)

This message response text is localized into the language specified by using the https://schemas.microsoft.com/cdo/configuration/languagecode field in the Configuration object.

The Reply method puts the sender of the original message in the To property of the new message but removes all other recipients and any attachments. If the message contains a ReplyTo field, the Reply method sets the IMessage.To property to this ReplyTo field; otherwise, it sets the To property to the From field.

Note

When you call the Reply method, the configuration fields in the reply message object are set with default values, overwriting any configuration values that were set prior to calling the Reply method. To avoid this, set the configuration fields for the message after you call the Reply method.

The ReplyAll method fills in the To line and removes any attachments as does the Reply method, but retains any recipients in the appropriate To or CC properties.

Example

Visual Basic

' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Exchange 2000 Server Library

' It is recommended that all input parameters be validated when they are
' first obtained from the user or user interface.
Sub ReplyToMessage(iMsg As CDO.Message)

    ' Assume we want to reply to all recipients.
    Dim iMsg2 As CDO.Message
    Set iMsg2 = iMsg.ReplyAll
    '   or Set iMsg2 = iMsg.Reply
    '      Set iMsg2 = iMsg.PostReply
    ' ..configure message object.
    '   Add any other recipients.
    iMsg2.TextBody = "I agree...please proceed." & vbCrLf & iMsg2.TextBody
    iMsg2.Send

End Sub

C++, IDL

#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import "c:\program files\common files\microsoft shared\cdo\cdoex.dll" no_namespace

// It is recommended that all input parameters be validated when they are
// first obtained from the user or user interface.
void replyToMessage( IMessagePtr& iMsg ) {

   // want to reply all

   IMessagePtr iMsg2;
   iMsg2 = iMsg->ReplyAll();
   // iMsg2 = iMsg->Reply();
   // iMsg2 = iMsg->PostReply();
   //     add any other recipients
   iMsg2->TextBody = "I agree...please proceed." + "\r\n" + iMsg2->TextBody;

   try {
      iMsg2->Send();
   }
   catch(_com_error e) {
      throw e;
   }
}

VBScript

Dim iDropDir
Dim iMsgs
Dim iMsg

Set iDropDir = CreateObject("CDO.DropDirectory")
Set iMsgs = iDropDir.GetMessages("c:\Inetpub\mailroot\Drop")
Set iMsg = iMsgs(1)

' want to reply all

Dim iMsg2
Set iMsg2 = iMsg.ReplyAll
' or Set iMsg2 = iMsg.Reply
'    Set iMsg2 = iMsg.PostReply
' ... configure message object
'     add any other recipients
iMsg2.TextBody = "I agree...please proceed." & vbCrLf & iMsg2.TextBody
iMsg2.Send