Platform SDK: Exchange 2000 Server |
[This is preliminary documentation and subject to change.]
Adds a BodyPart object to the BodyParts collection.
[Visual Basic] Function AddBodyPart([ByVal Index as Long = -1]) as IBodyPart [C++] HRESULT AddBodyPart( long Index = -1, IBodyPart** pVal); [IDL] HRESULT AddBodyPart( [in, defaultvalue(-1), optional] long Index, [out,retval] IBodyPart** pVal );
The AddBodyPart method creates a new BodyPart object in the BodyParts collection and then returns the IBodyPart interface on the new object. This method is essentially the same as using the IBodyParts.Add method on this object's BodyParts collection.
If an object already exists in the collection at the point you specify with the Index parameter, the new object is added in its place, and the index values of the existing object, and all following objects, are increased by one.
The MIME specification requires that a multipart item must hold all its content in subparts and not at its own level. Therefore, if AddBodyPart is called on a message that is not multipart and that holds content in its IMessage.HTMLBody or IMessage.TextBody properties, this content is converted to one or more subparts, which become the first elements of the new body parts collection created by AddBodyPart. The new object returned by AddBodyPart is added as the last element in this new collection.
When calling AddBodyPart, the ContentMediaType property is checked for the value "multipart". If not found, ContentMediaType is changed to "multipart/mixed" and a new BodyParts collection is created on the body part to which this body part is being added. If ContentMediaType was already "multipart/alternative", it is changed to "multipart/mixed", and the entire multipart/alternative structure is made a subpart of the body part to which you are adding the new body part. This is necessary because the new body part, being empty, cannot possibly be an alternative rendition of the other subparts of the multipart/alternative structure.
The ContentMediaType of the new body part is set to "application/octet-stream". This prevents the IMessage.HTMLBodyPart or IMessage.TextBodyPart property from mistaking the new body part for HTML or plain text in case it is not one of these types. You should set ContentMediaType to the appropriate value when you obtain the body part from the AddBodyPart method.
Body parts that will contain attachments may also be added directly via the IMessage.AddAttachment method. For simplicity it is recommended that you use the AddAttachment method to associate an attachment with the message.
Dim Flds as ADODB.Fields Dim Strm as ADODB.Stream Dim iMsg as New CDO.Message Dim iBp as CDO.BodyPart Set iBp = Msg.BodyPart.AddBodyPart Set Flds = iBp.Fields Flds("urn:schemas:mailheader:content-type") = "text/plain" Flds.Update Set Strm = iBp.GetDecodedContentStream Strm.WriteText "This is some text" Strm.Flush Set iBp = Msg.BodyPart.AddBodyPart Set Flds = iBp.Fields Flds("urn:schemas:mailheader:content-type") = "text/html" Flds.Update Set Strm = iBp.GetDecodedContentStream Strm.WriteText "<html><h1>This is some text</h1></html>" Strm.Flush Set Flds = iMsg.Fields Flds("urn:schemas:mailheader:content-type") = "multipart/alternative" Flds.Update