Platform SDK: CDO for Windows 2000

BodyParts CoClass

The BodyParts Component Object Model (COM) class defines an object that is used to manage a collection of BodyPart objects.

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

Implemented Interfaces

IBodyParts

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, and so on.

iMsg.Send
[C++]
#import "d:\program files\common files\system\ado\msado15.dll" no_namespace
#import "d:\winnt\system32\cdosys.dll" no_namespace
#include <iostream.h>
void main()
{
   CoInitialize(NULL);

   {
      IMessagePtr   iMsg(__uuidof(Message));
      IBodyPartPtr  iBp;
      IBodyPartsPtr iBps;
      _StreamPtr    Stm;
      _bstr_t       filepath;


      iMsg->To        = "\"SomeOne\" <someone@fake.microsoft.com>";
      iMsg->From      = "\"Another\" <another@fake.microsoft.com>";
      iMsg->Subject   = "Here is a subject for the message.";
      iMsg->TextBody  = "Here is a simple message with attachments.";

      /*
      ** attach an HTML file to message
      */
      try 
      {
         filepath  = _bstr_t(path) + _bstr_t("\\htmlfile.html");
         iMsg->AddAttachment(filepath,"","");
      }
      catch (_com_error e)
      {
         //...
      }

      /*
      ** Attach Word 2000 file to message
      */
      try {
         filepath  = _bstr_t(path) + _bstr_t("\\wordfile.doc");
         iMsg->AddAttachment(filepath,"","");
      }
      catch (_com_error e)
      {
         //...
      }
      
      /*
      ** Create MTHML body from www.microsoft.com
      */
      try 
      {
         iMsg->CreateMHTMLBody("http://www.microsoft.com",cdoSuppressAll,"","");
      }
      catch (_com_error e)
      {
         //...
      }

      /*
      ** Loop through body parts
      */ 
      iBp  =  iMsg;
      cout << "Root: content-type: " << iBp->ContentMediaType << endl;

      iBps = iBp->BodyParts;

      for(long i=1;i<=iBps->Count;i++) {
         iBp = iBps->Item[i];
         cout << "child bodypart media type: " << iBp->ContentMediaType << endl;
      }

      Stm    = iMsg->GetStream();
      Stm->SaveToFile(_bstr_t("message.eml"),adSaveCreateOverWrite);

   }
   CoUninitialize();
}

See Also

BodyPart COM Class