Platform SDK: Exchange 2000 Server

Attachments Property

[This is preliminary documentation and subject to change.]

Returns the collection of attachments for this message.

[Visual Basic]
Property Attachments as IBodyParts
read-only
[C++]
HRESULT get_Attachments(IBodyParts** pVal);
[IDL]
HRESULT [propget] Attachments([out,retval] IBodyParts** pVal);

Remarks

Attachments are stored as body parts in the message's body part hierarchy. 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 MIME-formatted messages by having the MIME header Content-Disposition set to "attachment." However, the exact status of a given body part insofar as its status as an attachment is implementation dependent.

The Attachments collection, although modeled using the IBodyParts interface (exposed by the returned BodyParts object) 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. For example, consider the following MIME hierarchy for a message:

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 body part 5 and one for body part 6 as defined in the example above. 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 header (urn:schemas:mailheader:content-disposition) is automatically set to "attachment."

Example

This code determines how many attachments a message has:

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"
  Else 
    MsgBox "Message has " & collAtts.Count & " attachments" 
  End If 
End Sub

See Also

IBodyParts Interface