Addressing the Message
Topic Last Modified: 2006-06-12
To send a message, you must specify at least one recipient address by using the IMessage.To, IMessage.CC, or IMessage.BCC property. To post an Network News Transfer Protocol (NNTP) message, you must specify at least one newsgroup address by using the IMessage.Newsgroups property.
Address Formats
The address formats are defined by various Internet standards:
SMTP Addresses
recipient@example.com
<recipient@example.com>
"Display Name" <recipient@example.com>
NNTP Newsgroup Names
comp.os.windows
comp.example.newsgroup1
Note
Multiple addressees for a message are separated with commas only. The semicolons used with MAPI clients such as Microsoft® Outlook® are not used.
"Mr. A" <a@example.com>, "Mr. B" <b@example.com>
A@example.com, <B@example.com>, "Mr. C" <c@example.com>
comp.example.newsgroup1, comp.example.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.Newsgroups property.
Example
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
iMsg.To = "someone@example.com"
iMsg.Newsgroups = "comp.example.newsgroup"
C++, IDL
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import "c:\program files\common files\microsoft shared\cdo\cdoex.dll" no_namespace
// ...
IMessagePtr iMsg(__uuidof(Message));
iMsg->To = "someone@example.com";
iMsg->Newsgroups = "comp.example.newsgroup";
VBScript
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
iMsg.To = "someone@example.com"
iMsg.Newsgroups = "comp.example.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 note applies to the To, CC, BCC, FollowUpTo, and Newsgroup properties. For example:
iMsg.To = "someone@example.com"
iMsg.To = iMsg.To & ",another@example.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 that are 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.
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:mailheader:to") = "someone@example.com"
.Item("urn:schemas:mailheader:from") = "<another@example.com>"
.Item("urn:schemas:mailheader:cc") = "<thirdperson@example.com>"
.Update
End With
' ..
C++, IDL
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import "c:\program files\common files\microsoft shared\cdo\cdoex.dll" no_namespace
// ...
IMessagePtr iMsg(__uuidof(Message));
FieldsPtr Flds;
Flds = iMsg->Fields;
Flds->Item["urn:schemas:mailheader:to"]->Value =
_variant_t("someone@example.com");
Flds->Item["urn:schemas:mailheader:from"]->Value =
_variant_t("<another@example.com>");
Flds->Item["urn:schemas:mailheader:cc"]->Value =
_variant_t("<thirdperson@example.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@example.com"
.Item("urn:schemas:mailheader:from") = "<another@example.com>"
.Item("urn:schemas:mailheader:cc") = "<thirdperson@example.com>"
.Update
End With
See Also
Other Resources
IMessage.To
IMessage.CC
IMessage.BCC
IMessage.From
urn:schemas:mailheader: Namespace
urn:schemas:httpmail: Namespace