Platform SDK: CDO for Windows 2000 |
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.
The address formats are defined by various Internet standards:
recipient@microsoft.com <recipient@microsoft.com> "Display Name" <recipient@microsoft.com>
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.
' 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"
#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";
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:
' 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 ' ..
#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();
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