다음을 통해 공유


Creating MIME-Formatted Messages

Topic Last Modified: 2006-06-12

By default, the Collaboration Data Objects (CDO) components construct message body content using Multipurpose Internet Mail Extensions (MIME) encoding format. This process is controlled by using the IMessage.MIMEFormatted property, which defaults to True. There are many ways to create the MIME content hierarchy in a message. In most cases, when adding an attachment or creating a MIME Encapsulation of Aggregate HTML Documents (MHTML) message, the IMessage interface exposes methods that automatically structure the MIME content and manage the underlying details. These methods include IMessage.AddAttachment and IMessage.CreateMHTMLBody. To add attachments to a message in UUEncoded format, set IMessage.MIMEFormatted to False.

In many cases, you might need to manually construct all or part of the body part hierarchy.

Objects that participate in the body part hierarchy for a message expose implementations of the IBodyPart interface. For example, each instance of the BodyPart and Message Component Object Model (COM) classes represents one body part in the hierarchy of a MIME-encoded message. Both BodyPart and Message instances expose the IBodyPart interface to facilitate manipulation of the body part's content and properties. The IBodyPart.BodyParts collection contains the child BodyPart objects for the object and is therefore used to navigate down the hierarchy of objects. To navigate up the hierarchy from an object, you use the IBodyPart.Parent property.

The Message object acts as the root of the MIME hierarchy. In standard object-oriented fashion, the hierarchies extend in patterns of BodyPart -> BodyParts -> BodyPart until a terminating (leaf) node in the hierarchy is reached.

When using methods such as IMessage.CreateMHTMLBody or IMessage.AddAttachment, or the HTMLBody property on the message, the MIME hierarchy is constructed automatically. You do not need to manually add the BodyPart objects that contain the various content parts.

In many cases, you might want to manually create the BodyPart hierarchy. To do so, you can use the IBodyPart.AddBodyPart method to add child body parts to the object. Alternatively, you can access the IBodyPart.BodyParts collection explicitly and use the IBodyParts.Add method to add the new body part. Both methods create a new BodyPart instance and return an object reference on the newly added object. Using this returned interface, you can then set any fields for the object using the IBodyPart.Fields collection. For body parts that contain content, use the appropriate Stream object to populate the content. Access the BodyPart Stream object by using either IBodyPart.GetEncodedContentStream or IBodyPart.GetDecodedContentStream.