Add Method (CDONTS Attachments Collection)

Add Method (CDONTS Attachments Collection)

The Add method creates and returns a new Attachment object in the Attachments collection.

Syntax

        Set
         objAttach = collAttachments.Add( [name] [, type] [, source] [, ContentLocation] [, ContentBase] ) 

objAttach

On successful return, contains the new Attachment object.

collAttachments

Required. The Attachments collection object.

name

Optional. String. The display name of the attachment. The default value is an empty string. To allow a user to click on the attachment that appears in the message and activate an associated application, supply the full file name, including the file extension.

type

Optional. Long. The type of attachment; either CdoFileData or CdoEmbeddedMessage. The default value is CdoFileData.

source

Optional. String or Object. The path and file name of the file containing the data for the attachment, or the Message object to be embedded. The path and file name must be in the appropriate format for the attachment type, specified by the type parameter. The default value is an empty string.

ContentLocation

Optional. String. The content location header for the appropriate body part of a MIME message attachment.

ContentBase

Optional. String. The content base header for the appropriate body part of a MIME message attachment.

Remarks

The name, type, source, ContentLocation, and ContentBase parameters correspond to the Name, Type, Source, ContentLocation, and ContentBase properties of the Attachment object. The source parameter is also closely related to the ReadFromFile method's fileName parameter.

You can supply the data for the attachment at the same time that you add it to the collection. The Add method operates differently depending on the value of the type parameter. The following table describes its operation.

Value of type parameter

Value of source parameter

CdoFileData

Specifies a full path and file name that contains the data for the attachment, for example C:\DOCUMENT\BUDGET.XLS. Must be supplied with the Add method. The data is read into the attachment.

CdoEmbeddedMessage

Specifies the Message object to be embedded. The message is copied into the attachment.

If the type parameter is set to CdoEmbeddedMessage, any setting of the name parameter is ignored in the current version of CDO for NTS. If the MessageFormat property of the parent Message object is set to CdoMime, the embedded message's Subject property is used for the attachment name. If the parent message's MessageFormat is CdoText, CDO for NTS randomly creates an attachment name in the format ATT00099.EML.

You should set the message's MessageFormat to CdoMime if you are running with the Microsoft® Exchange Server and plan to add attachments of type CdoEmbeddedMessage. This allows the greatest flexibility in opening and reading such an attachment.

The attachment is saved in persistent storage when you call the Send method on the Message object containing the Attachments collection.

The Add method returns CdoE_NO_ACCESS when called on a message in the Inbox.

The CDO for NTS Library does not permit any modifications to messages in the Inbox, other than deleting the entire message. Prohibited modifications include adding, deleting, or modifying any attachment; adding, deleting, or modifying any recipient; and modifying any message property, even one with read/write access.

See Also

Concepts

Attachments Collection Object (CDONTS Library)