Bagikan melalui


urn:schemas:mailheader: Namespace

urn:schemas:mailheader: Namespace

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 the raw message header property must RFC 1522-encode non US-ASCII characters or the header value will be 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 typos and extra typing.

Example

The following example demonstrates 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 MIME headers set manually.

This code is for illustrative purposes only.

Dim iMsg as New CDO.Message
Dim Flds as ADODB.Fields
With iMsg
  .To   = """Someone"" <example@example.com>"
  .From = """Me"" <example@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 Windows 2000"
      ' I add a custom header here
     .Item("urn:schemas:mailheader:Myheader")= "some value"
     .Update
     .Resync
   End With ' Flds
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
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import <cdosys.dll> no_namespace

void main()
{
  CoInitialize(NULL);
  {

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

    iMsg->To      = "\"Someone\" <example@example.com>";
    iMsg->From    = "\"Me\" <example@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 = "some 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();
}