The Add method creates and returns a new Attachment object in the Attachments collection.
Set objAttach = collAttachments.Add( [name] [, type] [, source] [, ContentLocation] [, ContentBase] )
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.