Add Method (CDONTS Messages Collection)

The Add method creates and returns a new Message object in the Messages collection.

Syntax

Set objMessage = collMessages.Add( [subject] [, text] [, importance] ) 
 
objMessage
On successful return, represents the new Message object added to the collection.
collMessages
Required. The Messages collection object.
subject
Optional. String. The subject line for the message.
text
Optional. IStream object or String. The text of the message.
importance
Optional. Long. The importance associated with the message.

Remarks

The subject, text, and importance parameters correspond to the Subject, Text, and Importance properties on the Message object.

You must create all new messages in the Outbox folder.

Only C/C++ and Java programs can use an IStream object for the text parameter. They should pass an IUnknown object that returns an IStream interface in response to QueryInterface. Microsoft® Visual Basic® supports the IDispatch interface and not IUnknown, so it cannot use an IStream object.

Example

This code fragment replies to an original message:

' from the sample function Util_ReplyToConversation 
Set objOutbox = objSession.GetDefaultFolder(CdoDefaultFolderOutbox) 
Set objNewMsg = objOutbox.Messages.Add 
' verify objNewMsg created successfully ... then supply properties 
Set objSenderAE = objOriginalMsg.Sender ' sender as AddressEntry 
With objNewMsg 
   .Text = "Here is a reply to your message." ' new text 
   .Subject = objOriginalMsg.Subject ' copy original properties 
   Set objRecip = .Recipients.Add(name:=objsenderAE.Name, _ 
                type:=CdoTo, _ 
                address:=objSenderAE.Type & ":" & objSenderAE.Address) 
   ' ** the preceding line is not strictly necessary with CDO for NTS, 
   ' ** but it allows this code to run with CDO for Exchange, where 
   ' ** Recipient.Address requires a FULL address concatenated from 
   ' ** AddressEntry.Type, ":", and AddressEntry.Address 
   .Send 
End With 
 

© 1997 by Microsoft Corporation. All rights reserved.