This documentation is archived and is not being maintained.

Attachments Property

Exchange Server 2003

Attachments Property

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The Attachments property specifies the collection of attachments for this message. This property is read-only.

Applies To

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In



        [Visual Basic]Property Attachments As IBodyParts
        [C++]HRESULT get_Attachments(IBodyParts** pVal);


Returned reference to an IBodyParts Interface.


Attachments are stored as body parts in the body part hierarchy of a message. The Attachments property returns a BodyParts collection that contains BodyPart objects, each of which contains an attachment to the message. In most cases, attachments are flagged as attachments in Multipurpose Internet Mail Extensions (MIME)-formatted messages by having the MIME header Content-Disposition set to "attachment." However, the status of a given body part as an attachment is implementation-dependent.

Although the Attachments collection resembles the IBodyParts interface (exposed by the returned BodyParts object), it is not the same as the collection returned by the IBodyPart.BodyParts collection for the object exposing IMessage. When you request the IMessage.Attachments collection, the object returns a collection of only those BodyPart objects deemed to contain an attachment to the message. The following MIME hierarchy for a message specifies an attachment:

1. Content-Type: multipart/mixed
2.    Content-Type: multipart/alternative
3.       Content-Type: text/plain
           (text content here)
4.       Content-Type: text/html
           (html content here)
5.    Content-Type: application/octet-stream
      Content-Disposition: attachment
        (content here)
6.    Content-Type: application/msword
      Content-Disposition: attachment
        (content here)

In this case, the IMessage.Attachments property would return a BodyParts collection containing two BodyPart objects: one for body part 5 and one for body part 6 as defined in the preceding example. The IBodyPart.BodyParts property would return a BodyParts collection containing three BodyPart objects: one for body part 2, one for body part 5, and one for body part 6.

When you add body parts using the IBodyParts interface passed by the Attachments property, the content-disposition Field (urn:schemas:mailheader:content-disposition) is automatically set to "attachment."


The following code determines how many attachments a message has:

        [Visual Basic]

Sub GetAttachmentCount(iMsg As CDO.Message)
  Dim collAtts As CDO.IBodyParts
  Set collAtts = iMsg.Attachments
  If collAtts.Count = 0 Then
    MsgBox "Attachments collection is empty"
    MsgBox "Message has " & collAtts.Count & " attachments"
  End If
End Sub

See Also

IBodyParts Interface