Platform SDK: CDO for Windows 2000

Sending and Posting Messages

To send a message, use the IMessage.Send method. Before you can send a message, you must set the sender and at least one recipient. 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 Newgroups 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 Windows 2000 Library
Dim iMsg as New CDO.Message
' configure object here if necessary
With iMsg
   .From     = "Someone@Somewhere.Microsoft.com"
   .To       = "SomeoneElse@Somewhere.Microsoft.com"
   .Subject  = "Your lights are on, but no one is home"
   .TextBody = "You left your lights on this morning."
   .Newsgroups = "somewhere.general"
   .Send
   .Post
End With

Set iMsg = Nothing
[C++,IDL]
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import <cdosys.dll> no_namespace
// ...
IMessagePtr iMsg(__uuidof(Message));
iMsg->From     = "Someone@Somewhere.microsoft.com";
iMsg->To       = "SomeoneElse@Somewhere.microsoft.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->Send();
iMsg->Post();
[VBScript]
Const g_bDebug = True
Dim iMsg
Dim iConf
Dim Flds
Set iMsg = CreateObject("CDO.Message")

Set iConf = iMsg.Configuration
Set Flds = iConf.Fields
Flds(cdoPostUsingMethod) = cdoPostUsingPickup
Flds(cdoSendUsingMethod) = cdoSendUsingPickup
Flds(cdoSMTPServerPickupDirectory) = "c:\inetpub\mailroot\pickup"
Flds(cdoNNTPServerPickupDirectory) = "c:\inetpub\nntpfile\pickup"
Flds(cdoPostUserReplyEmailAddress) = "stevebio@microsoft.com"
Flds(cdoPostEmailAddress)          = "stevebio@microsoft.com"
Flds(cdoSendUserReplyEmailAddress) = "stevebio@microsoft.com"
Flds(cdoSendEmailAddress)          = "stevebio@microsoft.com"

Flds(cdoLanguageCode)              = "en-us"
Flds(cdoAutoPromoteBodyParts)      = False
Flds(cdoFlushBuffersOnWrite)       = True
Flds.Update
Set Flds = Nothing

With iMsg
   .From         = "stevebioe@microsoft.com"
   .CC           = "stevebio@microsoft.com"
   .Subject      = "Your lights are on, but no one is home"
   .TextBody     = "You left your lights on this morning."
   .Newsgroups   = "somewhere.general"

   ' Here, we post the message
   If g_bDebug Then
     MsgBox .GetStream.ReadText
   Else 
    .Post
   End If

   ' Now, we ready the message for SMTP
   .Newsgroups    = ""
   .To            = "SomeoneElse@Somewhere.microsoft.com"
   ' Request an Mail Disposition Notification from Recipients
   .Fields(cdoDispositionNotificationTo) = "me@microsoft.com"
   .Fields.Update

   If g_bDebug Then
     MsgBox .GetStream.ReadText
   Else 
    .Send
   End If

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.

See Also

Configuring the Message Object

IMessage.Send Method

IMessage.Post Method