Sending and Posting Messages

Sending and Posting Messages

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

To send a message, use the IMessage.Send method. Before you can send a message, you must set at least one recipient address and one sender address. You can use the To and From properties for the Message object to do so.

To post a message, use the IMessage.Post method. Before you can post a message, you must set at least the From, Subject, and Newsgroups message header fields for the object. You can use either the IMessage.From, IMessage.Subject, and IMessage.Newsgroups properties for the Message object.

The following example demonstrates these steps using IMessage interface properties and fields in the IMessage.Fields collection.

Visual Basic

' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Exchange 2000 Server Library
' ..
Dim iMsg As New CDO.Message
' configure object here if necessary
With iMsg
   .From = "Someone@Somewhere.example.com"
   .CC = "Another@example.com"
   .Subject = "Your lights are on, but no one is home"
   .TextBody = "You left your lights on this morning."
   .Newsgroups = "somewhere.general"
   .Post
   .Newsgroups = ""
   .To = "SomeoneElse@Somewhere.example.com"
   .Fields(cdoDispositionNotificationTo) = "Someone@somewhere.example.com"
   .Fields.Update
   .Send
End With

Set iMsg = Nothing

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
// ...
IMessagePtr iMsg(__uuidof(Message));
iMsg->From     = "Someone@Somewhere.example.com";
iMsg->CC       = "Another@example.com";
iMsg->Subject  = "Your lights are on, but no one is home";
iMsg->TextBody = "You left your lights on this morning.";
iMsg->Newsgroups = "somewhere.general";
iMsg->Post();
iMsg->Newsgroups = "";
iMsg->To       = "SomeoneElse@Somewhere.example.com";
iMsg->Fields->Item[cdoDispositionNotificationTo]->Value =
_variant_t("someone@somewhere.example.com");
iMsg->Fields->Update();
iMsg->Send();
iMsg = NULL;

VBScript

Dim iMsg
Set iMsg = CreateObject("CDO.Message")
' configure object here if necessary
With iMsg
   .From     = "Someone@Somewhere.example.com"
   .CC       = "another@example.com"
   .Subject  = "Your lights are on, but no one is home"
   .TextBody = "You left your lights on this morning."
   .Newsgroups = "somewhere.general"
   .Post

   .Newsgroups = ""
   .To       = "SomeoneElse@Somewhere.example.com"
   .Fields(cdoDispositionNotificationTo) =
"someone@somewhere.example.com"
   .Fields.Update
   .Send
End With

Set iMsg = Nothing

The mechanism for sending or posting messages is controlled through configuration settings associated with the object. For more information, see Configuring the Message Object.

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.