Bagikan melalui


IConfiguration Interface

IConfiguration Interface

The IConfiguration interface defines properties and methods that you can use to access configuration information for Microsoft Collaboration Data Objects (CDO) objects.

  • IID
    CD000022-8B95-11D1-82DB-00C04FB1625D
  • Extends
    IDispatch

Member Summary

Properties

Name Type Description

Fields

(Read-only)

ADODB.Fields

Fields*

The Fields collection for the object.

Methods

Name Description

Load

Loads the specified configuration.

GetInterface

Reserved for future use.

Remarks

You can access configuration settings on implementing objects by using the IConfiguration interface. The Fields property references an ADO Fields collection, and each Field object in the collection contains a name/value pair that defines part of a particular configuration. Consult the appropriate fields section of the reference for a list of valid fields to use. Most field names associated with configuration settings reside in the https://schemas.microsoft.com/cdo/configuration/ namespace.

Example

The following example demonstrates use of the IConfiguration interface on a CDO Configuration object. When sending messages from a machine that does not have a Simple Mail Transport Protocol (SMTP) service installed, you must send the message using an SMTP service on the network. A Configuration object is created, populated with configuration information, and then associated with a Message object using the IMessage.Configuration property. The SMTP server name, port, user display name, e-mail address, and credentials are all set as a part of the configuration. The table below lists the values used. Note that a field's fully qualified name must be used for reference. For configuration fields, all field names are prefixed with the https://schemas.microsoft.com/cdo/configuration/ namespace; for example, the fully qualified name for the smtpserver field is https://schemas.microsoft.com/cdo/configuration/smtpserver. To save space, the fields in the table below are listed without the namespace prefix.

Namespace: https://schemas.microsoft.com/cdo/configuration/

Field Value

smtpserver

mail.example.com

smtpserverport

67

smtpaccountname

My Name

sendemailaddress

"MySelf" <example@example.com>

smtpauthenticate

cdoBasic (1)

sendusername

domain\username

sendpassword

password

Smtpusessl

True (VARIANT_TRUE)

Sendusing

cdoSendUsingPort (2)

Once the Configuration object has been populated with relevant configuration information and associated with the Message object, the message is sent. In the following example, the CdoConfiguration module constants are used to identify the desired field. These constants are simply the full names of the fields in the namespace. For example, the CdoConfiguration constant cdoSMTPServer is equal to the string “https://schemas.microsoft.com/cdo/configuration/smtpserver.”

' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Dim iConf as new CDO.Configuration
Dim Flds as ADODB.Fields

Set Flds = iConf.Fields
Flds(cdoSendUsingMethod)          = cdoSendUsingPort ' 2
Flds(cdoSMTPServer)               = "mail.example.com"
Flds(cdoSMTPServerPort)           = 67
Flds(cdoSMTPAccountName)          = "My Name"
Flds(cdoSMTPAuthenticate)         = cdoBasic ' 1

' IMPORTANT: Storing user names and passwords inside source code
' can lead to security vulnerabilities in your software. Do not
' store user names and passwords in your production code.
Flds(cdoSendUserName)             = "domain\username"
Flds(CdoSendPassword)             = "password"

Flds(cdoSendEmailAddress)         = """MySelf"" <example@example.com>"
Flds(cdoSMTPUseSSL)               = True
Flds.Update

Dim iMsg as New CDO.Message
Set iMsg.Configuration = iConf
  ' ... compose message; add attachments, etc
iMsg.Send
  
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace raw_interfaces_only
#import "c:\winnt\system32\cdosys.dll" no_namespace raw_interfaces_only
#include "cdosysstr.h"
#include "cdosyserr.h"
#include <atlbase.h>
#include <atlimpl.cpp>

main( ){

  CoInitialize(NULL);
  HRESULT hr = S_OK;
  {
    // Create Configuration Object
    CComPtr<IConfiguration> pConf;
    hr = pConf.CoCreateInstance(L"CDO.Configuration");

    CComPtr<Fields> pFields;
    hr = pConf->get_Fields(&pflds);

     CComPtr<Field> pfld;
     hr = pFields->get_Item(CComVariant(cdoSMTPServer),&pfld);
     hr = pfld->put_Value(CComVariant("mailserver"));

     hr = pFields->get_Item(CComVariant(cdoSMTPServerPort),&pfld);
     hr = pfld->put_Value(CComVariant((long)67));

     hr = pFields->get_Item(CComVariant(cdoSMTPAccountName),&pfld);
     hr = pfld->put_Value(CComVariant("My Name"));

     hr = pFields->get_Item(CComVariant(cdoSendEmailAddress),&pfld);
     hr = pfld->put_Value(CComVariant("\MySelf\" <example@example.com>"));

     hr = pFields->get_Item(CComVariant(cdoSTMPAuthenticate),&pfld);
     hr = pfld->put_Value(CComVariant((long)cdoBasic));

     hr = pFields->get_Item(CComVariant(cdoSendUserName),&pfld);
     hr = pfld->put_Value(CComVariant("domain\\username"));

     hr = pFields->get_Item(CComVariant(cdoSendPassword),&pfld);
     hr = pfld->put_Value(CComVariant("password"));

     hr = pFields->get_Item(CComVariant(cdoSMTPUseSSL),&pfld);
     hr = pfld->put_Value(CComVariant(VARIANT_TRUE));

    hr = pFields->get_Item(CComVariant(cdoSendUsingMethod),&pfld);
    hr = pfld->put_Value(CComVariant((long)cdoSendUsingPort));

    hr = pFields->Update();

    CComPtr<IMessage> pMsg;
    pMsg.CoCreateInstance(L"CDO.Message");
    pMsg->putref_Configuration(pConf);

    // ... compose message; add attachments, etc

    pMsg->Send();

  }
  CoUninitialize();
}
  
Dim iConf
Set iConf = CreateObject("CDO.Configuration")
Dim Flds as ADODB.Fields
Set Flds = iConf.Fields
Flds(cdoSendUsingMethod)          = cdoSendUsingPort ' 2
Flds(cdoSMTPServer)               = "mail.example.com"
Flds(cdoSMTPServerPort)           = 67
Flds(cdoSMTPAccountName)          = "My Name"
Flds(cdoSMTPAuthenticate)         = cdoBasic ' 1

' IMPORTANT: Storing user names and passwords inside source code
' can lead to security vulnerabilities in your software. Do not
' store user names and passwords in your production code.
Flds(cdoSendUserName)             = "domain\username"
Flds(CdoSendPassword)             = "password"

Flds(cdoSendEmailAddress)         = """MySelf"" <example@example.com>"
Flds(cdoSMTPUseSSL)               = True
Flds.Update

Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Set iMsg.Configuration = iConf
  ' ... compose message; add attachments, etc
iMsg.Send