Sending and Posting Messages

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.

' 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 = "example@server.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 = "example2@server.example.com"
   .Fields(cdoDispositionNotificationTo) = "example@server.example.com"
   .Fields.Update
   .Send
End With

Set iMsg = Nothing

#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import <cdosys.dll> no_namespace
// ...
IMessagePtr iMsg(__uuidof(Message));
iMsg->From     = "example@server.example.com";
iMsg->To       = "example2@server.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->Send();
iMsg->Post();
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) = "example@example.com"
Flds(cdoPostEmailAddress)          = "example@example.com"
Flds(cdoSendUserReplyEmailAddress) = "example@example.com"
Flds(cdoSendEmailAddress)          = "example@example.com"

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

With iMsg
   .From         = "example@example.com"
   .CC           = "example@example.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            = "example2@server.example.com"
   ' Request an Mail Disposition Notification from Recipients
   .Fields(cdoDispositionNotificationTo) = "example@example.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

Concepts

Configuring the Message Object
Send Method
Post Method