Platform SDK: CDO for Windows 2000 |
The fields needed for typical MIME messages are automatically set when BodyPart objects are created. For example, when you set the IMessage.HTMLBody property with the IMessage.AutoGenerateTextBody property set to True, the IMessage.TextBody property is automatically generated. In addition, the IBodyPart.ContentMediaType property for the root part is automatically set to multipart/alternative, with the two subparts containing the text and HTML versions of the message set to text/plain and text/html respectively.
For more complex messages that are formatted in MIME, you may need to set the header fields directly. All fields are stored in a Microsoft® Active® X Data Objects (ADO) Fields collection as name/value pairs. The mail header fields used with body parts reside in the urn:schemas:mailheader: namespace. Common fields such as urn:schemas:mailheader:content-type are also exposed as properties of the IBodyPart interface.
The following example shows how to set the ADO field urn:schemas:mailheader:content-language of the root body part of a simple message to German ("de").
' Reference to Microsoft ActiveX Data Objects 2.5 Library ' Reference to Microsoft CDO for Windows 2000 Library Dim iMsg As New CDO.Message Dim iBp As CDO.IBodyPart Set iBp = iMsg Dim Flds as ADODB.Fields Set Flds = iBp.Fields Flds("urn:schemas:mailheader:content-language") = "de" Flds.Update
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace #import <cdosys.dll> no_namespace // ... IMessagePtr iMsg(__uuidof(Message)); IBodyPartPtr iBp; FieldsPtr Flds; iBp = iMsg; Flds = iBp->Fields; Flds->Item["urn:schemas:mailheader:content-language"] = _variant_t("de"); Flds->Update();
Dim iMsg Set iMsg = CreateObject("CDO.Message") Dim iBp Set iBp = iMsg.BodyPart Dim Flds Set Flds = iBp.Fields Flds("urn:schemas:mailheader:content-language") = "de" Flds.Update
urn:schemas:mailheader:content-type Field