BodyParts CoClass
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
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
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://server.example.com/page.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
#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\" <example@server.example.com>";
iMsg->From = "\"Another\" <another@example.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 server.example.com
*/
try
{
iMsg->CreateMHTMLBody("http://server.example.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();
}