Platform SDK: CDO for Windows 2000

Addressing the Message

To send a message, you must specify at least one recipient by using the IMessage.To, IMessage.CC, or IMessage.BCC property. To post a message using NNTP, you must specify at least one newsgroup by using the IMessage.Newsgroups property.

Address Formats

The address formats are defined by various Internet standards:

SMTP Addresses
recipient@microsoft.com
<recipient@microsoft.com>
"Display Name" <recipient@microsoft.com>
NNTP Newsgroup Names
comp.os.windows
comp.microsoft.newsgroup1

Note   Multiple addressees for a message are separated with commas (as opposed to semicolons, which are used with Messaging Application Programming Interface (MAPI) clients such as Microsoft® Outlook®).

"Mr. A" <a@microsoft.com>, "Mr. B" <b@microsoft.com>
A@microsoft.com, <B@microsoft.com>, "Mr. C" <c@microsoft.com>

comp.microsoft.newsgroup1, comp.microsoft.newsgroups2

All addresses must be complete addresses or newsgroup names. The following examples show how to address a message by using the IMessage.To or IMessage.Newsgroup property.

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

iMsg.To         = "someone@microsoft.com"
iMsg.Newsgroups = "comp.microsoft.newsgroup"
[C++,IDL]
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import <cdosys.dll> no_namespace
// ...
IMessagePtr iMsg(__uuidof(Message));

iMsg->To         = "someone@microsoft.com";
iMsg->Newsgroups = "comp.microsoft.newsgroup";
[VBScript]
Dim iMsg
Set iMsg = CreateObject("CDO.Message")

iMsg.To         = "someone@microsoft.com"
iMsg.Newsgroups = "comp.microsoft.newsgroup"

Note   Trailing commas are removed from address strings by the address field parser each time you set an address property. To concatenate address fields, place the comma at the beginning of the string being added. You can also concatenate the addresses prior to setting the value of the address field. This applies to the To, CC, BCC, FollowUpTo, and Newsgroup properties. For example:

iMsg.To = "someone@microsoft.com"
iMsg.To = iMsg.To & ",another@microsoft.com"

The IMessage interface exposes properties that relate to the most common mail header fields such as To, From, Cc, Bcc, Newsgroups and FollowUpTo; however, the complete list of headers for the message is contained in the IMessage.Fields collection. Fields used with a Message object reside in the urn:schemas:mailheader: and urn:schemas:httpmail: namespaces. Consequently, you can use the Fields collection to set mail header fields used to address the message if desired:

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

Dim Flds as ADODB.Fields
Set Flds = iMsg.Fields
With Flds
  .Item("urn:schemas:mailheader:to")   = "someone@microsoft.com"
  .Item("urn:schemas:mailheader:from") = "<another@microsoft.com>"
  .Item("urn:schemas:mailheader:cc")   = "<thirdperson@microsoft.com>"
  .Update
End With
  ' ..
[C++,IDL]
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import <cdosys.dll> no_namespace
// ...
IMessagePtr iMsg(__uuidof(Message));

FieldsPtr Flds;
Flds = iMsg->Fields;
Flds->Item["urn:schemas:mailheader:to"]->Value = _variant_t("someone@microsoft.com");
Flds->Item["urn:schemas:mailheader:from"]->Value = _variant_t("<another@microsoft.com>");
Flds->Item["urn:schemas:mailheader:cc"]->Value = _variant_t("<thirdperson@microsoft.com>");
Flds->Update();
[VBScript]
Dim iMsg
Set iMsg = CreateObject("CDO.Message")

Dim Flds
Set Flds = iMsg.Fields
With Flds
  .Item("urn:schemas:mailheader:to")   = "someone@microsoft.com"
  .Item("urn:schemas:mailheader:from") = "<another@microsoft.com>"
  .Item("urn:schemas:mailheader:cc")   = "<thirdperson@microsoft.com>"
  .Update
End With

See Also

IMessage.To

IMessage.CC

IMessage.BCC

IMessage.From

urn:schemas:mailheader: Namespace