Platform SDK: Exchange 2000 Server

BodyParts CoClass

[This is preliminary documentation and subject to change.]

Defines an object used to manage a collection of BodyPart objects.

CLSID
Not applicable
ProgID
Not applicable
Type Library
Microsoft CDO for Windows 2000 Library,
Microsoft CDO for Microsoft Exchange Server
Inproc Server
CDOSYS.DLL, CDOEX.DLL
Threading Model
Both

Implemented Interfaces

IBodyParts

Supported IDataSource Bindings

None

Remarks

Instances of the BodyParts COM class cannot be created directly. An object reference is always returned by BodyParts properties on other interfaces, such as the IBodyPart::BodyParts property.

Example

[Visual Basic]
Dim iMsg as new CDO.Message
Dim iBp as CDO.IBodyPart
Dim iBps as CDO.IBodyParts

iMsg.AddAttachment "c:\somefile.html"
iMsg.AddAttachment "c:\anotherfile.doc"
iMsg.CreateMHTMLBody "http://myserver/mypage.html", cdoSuppressAll

Set iBp = iMsg
Debug.Print "Root content-type: " & iBp.ContentMediaType
Set iBps = iBp.BodyParts

' loop through attachments
Dim i as Integer
For Each iBp in iBps
  Debug.Print "Level 1, item " & i & " " & iBp.ContentMediaType  
  i = i + 1
Next iBp
' set recipients, etc

iMsg.Send
[C++]
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import "c:\winnt\system32\cdosys.dll" no_namespace
#include <iostream.h>
#include <assert.h>

main(){
  CoInitialize(NULL);  // single-threaded apartment
  {
   IBodyPartPtr   iBp;
   IBodyPartsPtr iBps;
   IMessagePtr iMsg(__uuidof(Message));

   iMsg->AddAttachment("c:\somefile.html","","");
   iMsg->AddAttachment("c:\anotherfile.doc","","");
   iMsg->CreateMHTMLBody("http://www.microsoft.com", cdoSuppressAll,"","");

   iBp = iMsg;
   // print the content media types for the body parts
   // this will print "multipart/mixed"
   cout << "Root content-type: " << iBp->ContentMediaType << endl;

   iBps = iBp->BodyParts;

   for(long i = 1;i<=iBps->Count;i++) {
     iBp = iBps->item[i];
     cout << "level 1, item " << i << " " << iBp->ContentMediaType << endl;
   }
   // in the above loop, you will get "multipart/alternative"
   // and, depending upon the attachments, something like
   // "text/html"
   // "application/octet-stream"

   // set recipients, etc

   iMsg->Send();
  }   
  CoUninitialize();
  return 0;
}