Partager via


urn:schemas:mailheader: Namespace

Topic Last Modified: 2006-06-11

The urn:schemas:mailheader: namespace defines fields that contain Internet standard message header values. Each field value (with a few exceptions) is stored as US-ASCII characters and is identical to the ASCII string found in the message stream. Non-US-ASCII characters are encoded according to the RFC 1522 specification. No conversion is performed when the property value is set or updated. An application that sets a raw message header property within this namespace must encode any non-US-ASCII characters as defined in RFC 1522. If these characters are not encoded, the header field value is corrupted.

String constants are provided in the C++ header file cdosysstr.h and type library, cdoMailHeader module, for each field name. You can use these constants when referring to the fields to avoid mistakes and extra typing.

Example

The following example demonstrates the use of the fields in the urn:schemas:mailheader: namespace. First, RFC 822 headers are added for a message. Next, body parts are added and the Multipurpose Internet Mail Extensions (MIME) headers are set manually.

This code is for illustrative purposes only.

Example

Visual Basic

Dim iMsg as New CDO.Message
Dim Flds as ADODB.Fields
With iMsg
  .To   = """SomeOne"" <someone@example.com>"
  .From = """Me"" <me@example.com>"
  .Subject = "Here is a sample message"

' Now set some custom mail headers using the raw fields collection
   Set Flds = .Fields
   With Flds
    .Item("urn:schemas:mailheader:X-Mailer")  = "Microsoft CDO for Microsoft Exchange"
      ' I add a custom header here
    .Item("urn:schemas:mailheader:Myheader")= "some value"
    .Update
   End With
End With ' iMsg

   ' Create a multipart/alternative (HTML) message below

   Dim iBp as CDO.IBodyPart
   Dim iBp2 as CDO.IBodyPart

   Set iBp = iMsg   '  get IBodyPart on Message object

   Set Flds = iBp.Fields
   Flds("urn:schemas:mailheader:content-type") = "multipart/alternative"
   Flds.Update

   Set iBp2 = iBp.AddBodyPart
   Set Flds = iBp2.Fields
   Flds("urn:schemas:mailheader:content-type") = "text/plain"
   Flds("urn:schemas:mailheader:content-transfer-encoding") = "quoted-printable"
   Flds.Update

   Dim Stm as ADODB.Stream
   Set Stm = iBp2.GetDecodedContentStream
   Stm.WriteText "This is a test", stWriteLine
   Stm.Flush

   Set iBp2 = iBp.AddBodyPart
   Set Flds = iBp2.Fields
   Flds("urn:schemas:mailheader:content-type") = "text/html"
   Flds("urn:schemas:mailheader:content-transfer-encoding") = "quoted-printable"
   Flds.Update

   Set Stm = iBp2.GetDecodedContentStream
   Stm.WriteText "This is a <i>test</i>", stWriteLine
   Stm.Flush

   iMsg.Send

C++

#import "d:\program files\common files\system\ado\msado15.dll" no_namespace
#import "c:\program files\common files\microsoft shared\cdo\cdoex.dll" no_namespace

void main()
{
  CoInitialize(NULL);
  {

    IMessagePtr iMsg(__uuidof(Message));
    FieldsPtr   Flds;
    _StreamPtr  pStm;

    iMsg->To      = "\"SomeOne\" <someone@example.com>";
    iMsg->From    = "\"Me\" <me@example.com>";
    iMSg->Subject = "This is a test message";
    // Now set some custom headers for the message
    Flds = iMsg->Fields;
    Flds->Item["urn:schemas:mailheader:X-Mailer"]->Value   = "Microsoft CDO for Windows 2000";
    Flds->Item["urn:schemas:mailheader:Myheader"]->Value = "come value";
    Flds->Update();

    IBodyPartPtr iBp;
    iBp = iMsg;
    IBodyPartPtr iBp2;
    Flds = iBp->Fields;
    Flds->Item["urn:schemas:mailheader:content-type"]->Value = "multipart/alternative";
    Flds->Update();

    iBp2 = iBp->AddBodyPart(-1);
    Flds = iBp2->Fields;
    Flds->Item["urn:schemas:mailheader:content-type"]->Value = "text/plain";
    Flds->Item["urn:schemas:mailheader:content-transfer-encoding"]->Value = "quoted-printable";
    Flds->Update();

    pStm = iBp2->GetDecodedContentStream();
    pStm->WriteText("This is a test",stWriteLine);
    pStm->Flush();

    iBp2 = iBp->AddBodyPart(-1);
    Flds = iBp2->Fields;
    Flds->Item["urn:schemas:mailheader:content-type"]->Value = "text/html";
    Flds->Item["urn:schemas:mailheader:content-transfer-encoding"]->Value = "quoted-printable";
    Flds->Update();

    pStm = iBp2->GetDecodedContentStream();
    pStm->WriteText("This is a <i>test</i>",stWriteLine);
    pStm->Flush();

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