Compartir a través de


Configuration CoClass

Topic Last Modified: 2006-06-13

Defines an object used to manage the configuration settings used with other Collaboration Data Objects (CDO).

CLSID

CD000002-8B95-11D1-82DB-00C04FB1625D

ProgID

CDO.Configuration

Type Library

Microsoft CDO for Windows 2000 Library

Microsoft CDO for Exchange 2000 Library

Inproc Server

CDOSYS.DLL, CDOEX.DLL

Threading Model

Both

Remarks

Configuration settings are made up of a set of fields (properties) that are simply name/value pairs. Each field is represented as a Microsoft® ActiveX® Data Objects (ADO) Field object contained in an ADO Fields collection. Most configuration fields used for messaging are in the https://schemas.microsoft.com/cdo/configuration/ namespace. For calendaring applications, you specify a time zone using the urn:schemas:calendar:timezone and urn:schemas:calendar:timezoneid fields, and a calendar folder URL using the "CalendarLocation" field.

To increase performance, you can share a single Configuration object among your other CDO objects, and cache the object for reuse. For example, you can gather the configuration information for a particular user in an ASP application Session_OnStart event, and then store the Configuration object in the ASP Session collection. When each ASP page within the session executes, you can retrieve the Configuration object from the Session collection and attach it to each object. You therefore increase performance by not re-creating and populating a Configuration object for each page or for each object you use.

Examples

Assume that the computer on which this example will run has neither a SMTP service nor Microsoft Outlook® Express installed. In this case, you need to send the message through some SMTP service on the network and must configure the Message object completely. Further assume that the SMTP service through which you intend to send messages requires that you authenticate yourself using basic (clear-text) authentication. An instance of the Configuration Component Object Model (COM) class is created and the configuration fields in the object are set with values such as the required SMTP server name, port, authentication, and user name and password. Additional values are set, such as the e-mail address, account name and reply e-mail address. The values used in the example are listed in the following table. Each field is in the https://schemas.microsoft.com/cdo/configuration/ namespace.

Field Value

smtpserver

fakesmtp.example.com

smtpserverport

25

sendusing

cdoSendUsingPort (2)

smtpaccountname

My Name

sendemailaddress

"My Self" <myself@example.com>

senduserreplyemailaddress

"Another" <another@example.com>

smtpauthenticate

cdoBasic (1)

sendusername

domain\username

sendpassword

password

After the Configuration object has been populated with relevant configuration information, the object reference is set on a Message object. The Message object uses the configuration information to send the message. In the examples that follow, the fully qualified field names are used to clarify the process. However, there are string constants (as type library modules) in the type library for each of these field names.


  ' Reference to Microsoft ActiveX Data Object 2.5 Library
  ' Reference to Microsoft CDO for Exchange 2000 Library
  Dim iConf as New CDO.Configuration
  Dim Flds as ADODB.Fields
  Set Flds = iConf.Fields

    ' The full field name strings are used below to clarify this process.
    ' The CDO for Windows 2000 type library contains string modules
    ' that provide these values as named constants.
    ' Use these module constants to avoid typos and so forth.

  Flds("https://schemas.microsoft.com/cdo/configuration/smtpserver") = "fakesmtp.example.com"
  Flds("https://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  Flds("https://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
    ' CdoSendUsing enum value =  2
  Flds("https://schemas.microsoft.com/cdo/configuration/smtpaccountname") = "My Name"
  Flds("https://schemas.microsoft.com/cdo/configuration/sendemailaddress") = """MySelf"" <myself@example.com>"
  Flds("https://schemas.microsoft.com/cdo/configuration/senduserreplyemailaddress") = """Another"" <another@example.com>"
  Flds("https://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
  Flds("https://schemas.microsoft.com/cdo/configuration/sendusername") = "domain\username"
  Flds("https://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
  Flds.Update

  ' The Item property on the Fields interface is the default.
  ' The Value property on the returned Field interface is the default.
  ' Fully expanded, each line would appear as follows:
  '
  ' Flds.Item("property").Value = [value]

  Dim iMsg as New CDO.Message
  Set iMsg.Configuration = iConf

  ' ... Compose message; add attachments and so forth.

' Configuration settings in Config object are used to send the message.
iMsg.Send



#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

main( ){

  CoInitialize(NULL);
  {
    IMessagePtr IMsg(__uuidof(Message));
    IConfigurationPtr iConfig = Msg->Configuration;

    FieldsPtr Flds;
    FieldPtr Fld;
    Flds = iConfig->Fields;

    // The full strings for field names are used to clarify the process.
    // The cdoex.h header file contains BSTR constants that
    // can be used to avoid typos and so forth.

    Flds->Item[_variant_t("https://schemas.microsoft.com/cdo/configuration/smtpserver")]->Value = _variant_t("fakesmtp.example.com") ;
    Flds->Item[_variant_t("https://schemas.microsoft.com/cdo/configuration/smtpserverport")]->Value = _variant_t((long)25) ;
    Flds->Item[_variant_t("https://schemas.microsoft.com/cdo/configuration/sendusing")]->Value = _variant_t((int)cdoSendUsingPort) ;
    // this value is 2
    Flds->Item[_variant_t("https://schemas.microsoft.com/cdo/configuration/smtpaccountname")]->Value = _variant_t("My Name") ;
    Flds->Item[_variant_t("https://schemas.microsoft.com/cdo/configuration/sendemailaddress")]->Value = _variant_t("\"MySelf\" <myself@example.com>") ;
    Flds->Item[_variant_t("https://schemas.microsoft.com/cdo/configuration/senduserreplyemailaddress")]->Value = _variant_t("\"Another\" <another@example.com>") ;
    Flds->Item[_variant_t("https://schemas.microsoft.com/cdo/configuration/smtpauthenticate")]->Value = _variant_t((long)cdoBasic) ;
    Flds->Item[_variant_t("https://schemas.microsoft.com/cdo/configuration/sendusername")]->Value = _variant_t("domain\\username") ;
    Flds->Item[_variant_t("https://schemas.microsoft.com/cdo/configuration/sendpassword")]->Value = _variant_t("password") ;
    Flds->Update();

    /*
    ** These string constants are available in the cdosys.h header file,
    ** but are not put in the cdosys.tlh file when #import runs.

       const BSTR cdoSMTPServer = = L"https://schemas.microsoft.com/cdo/configuration/smtpserver";

       and so on additionally for each of these:

       cdoSMTPServer
       cdoSMTPAccountName
       cdoSMTPAuthenticate
       cdoSendUsingMethod    (You can use the CdoSendUsing enumeration for this.)
       cdoSMTPServerPort
       cdoSendEmailAddress
       cdoSendUserName
       cdoSendPassword
       cdoSendUserReplyEmailAddress
    */

    iMsg->Configuration = iConfig;

    // ... Compose message; add attachments and so forth.

    iMsg->Send();

  }
  CoUninitialize();
}