다음을 통해 공유


Attachments Property (IMessage)

Topic Last Modified: 2006-12-01

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

Applies To

IMessage Interface

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In

CDOEX.DLL

Syntax

Property Attachments As IBodyParts

HRESULT get_Attachments(IBodyParts** pVal);

Parameters

Remarks

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."

Example

The following 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

Other Resources

IBodyParts Interface