Platform SDK: Exchange 2000 Server

Setting Message Header Fields

[This is preliminary documentation and subject to change.]

The most common header fields for messages are exposed as properties on the IMessage interface. However, all header fields are accessible in the IMessage.Fields collection. The header fields you can set using this collection reside in the urn:schemas:mailheader: and urn:schemas:httpmail: namespaces. Additionally, the http://schemas.microsoft.com/exchange/sensitivity field is available.

You can add other headers not present in the provided default schema by adding the header to the collection within the urn:schemas:mailheader: field namespace.

Note

Make sure to encode non US-ASCII characters when using the urn:schemas:mailheader: namespace using the mechanism defined in RFC 1522.

[Visual Basic]
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Exchange 2000 Server Library
' ..
Dim iMsg as New CDO.Message

Dim Flds as ADODB.Fields
Set Flds = iMsg.Fields

With Flds
  .Item("urn:schemas:httpmail:to")      = "someone@microsoft.com"
  .Item("urn:schemas:httpmail:from")   = "another@microsoft.com"
  .Item("urn:schemas:httpmail:cc")     = "thirdperson@microsoft.com"
  .Item("urn:schemas:httpmail:sender") = "myaddress@microsoft.com"

  .Item("urn:schemas:mailheader:myhdr") = "some value"
  .Item("urn:schemas:mailheader:X-Hdr") = "less value"

  .Update
End With
[C++,IDL]
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import "c:\exchsrvr\cdoex.dll" no_namespace
// ...
IMessagePtr iMsg(__uuidof(Message));

FieldsPtr Flds;
Flds = iMsg->Fields;

Flds->Item["urn:schemas:httpmail:to"]->Value
      = _variant_t("someone@microsoft.com");
Flds->Item["urn:schemas:httpmail:from"]->Value
      = _variant_t("another@microsoft.com");
Flds->Item["urn:schemas:httpmail:cc"]->Value
      = _variant_t("thirdperson@microsoft.com");
Flds->Item["urn:schemas:httpmail:sender"]->Value
      = _variant_t("myaddress@microsoft.com");

Flds->Item["urn:schemas:mailheader:myhdr"]->Value
     = _variant_t("some value");
Flds->Item["urn:schemas:mailheader:X-Header"]->Value
     = _variant_t("another value");
Flds->Update();
[VBScript]
Dim iMsg
Set iMsg = CreateObject("CDO.Message")

Dim Flds
Set Flds = iMsg.Fields

With Flds
  .Item("urn:schemas:httpmail:to")      = "someone@microsoft.com"
  .Item("urn:schemas:httpmail:from")   = "another@microsoft.com"
  .Item("urn:schemas:httpmail:cc")     = "thirdperson@microsoft.com"
  .Item("urn:schemas:httpmail:sender") = "myaddress@microsoft.com"
  .Item("urn:schemas:mailheader:myhdr") = "some value"
  .Item("urn:schemas:mailheader:X-Hdr") = "less value"
  .Update
End With

Tip   When using the Fields collection, always remember to call the Update method to commit any changes, deletions, or additions.

Note that in the example above, the Field.Item method was used to retrieve the Field object from the collection. You can also use the Fields.Append method. For CDO applications, the Item method will return the appropriate Field object regardless of whether it currently exists in the collection.

See Also

IMessage Interface

urn:schemas:mailheader: Namespace

urn:schemas:httpmail: Namespace

urn:schemas:mailheader:sensitivity