Tải bản đầy đủ (.pdf) (64 trang)

Tài liệu Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (969.89 KB, 64 trang )




Contents
Overview 1
Introduction to CDO 2
Using the CDO Library in Collaborative
Applications 12
Working with Messages and Message
Properties 20
Working with the CDO Object Model 29
Using the CDO Rendering Library in
Collaborative Applications 46
Lab A: Adding CDO Code to the Employee
Move Form 53
Review 58

Module 12: Integrating
Collaboration Data
Objects Within an
Outlook 2000 Solution


Information in this document is subject to change without notice. The names of companies,
products, people, characters, and/or data mentioned herein are fictitious and are in no way intended
to represent any real individual, company, product, or event, unless otherwise noted. Complying
with all applicable copyright laws is the responsibility of the user. No part of this document may
be reproduced or transmitted in any form or by any means, electronic or mechanical, for any
purpose, without the express written permission of Microsoft Corporation. If, however, your only
means of access is electronic, permission to print one copy is hereby granted.


Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual
property rights covering subject matter in this document. Except as expressly provided in any
written license agreement from Microsoft, the furnishing of this document does not give you any
license to these patents, trademarks, copyrights, or other intellectual property.

 1999 Microsoft Corporation. All rights reserved.

Microsoft, Active Desktop, Active Directory, ActiveX, BackOffice, Developer Studio, FrontPage,
JScript, MSDN, MSN, NetMeeting, Outlook, PivotChart, PivotTable, PowerPoint, Visual Basic,
Visual C++, Visual FoxPro, Visual InterDev, Visual J++, Visual SourceSafe, Visual Studio,
Windows, Windows Media, and Windows NT are either registered trademarks or trademarks of
Microsoft Corporation in the U.S.A. and/or other countries.

The names of companies, products, people, characters, and/or data mentioned herein are fictitious
and are in no way intended to represent any real individual, company, product, or event, unless
otherwise noted.

Other product and company names mentioned herein may be the trademarks of their respective
owners.


Project Advisor: Janet Wilson
Project Lead and Instructional Designer: Anne Bockman (Excell Data Corporation)
Instructional Designers: Josh Barnhill (Volt Technical) and Jo Berry (Exchange)
Lead Program Manager: Greg Bott
Program Managers: Colleena Carr and Chris Boar (Intl Vendor)
Graphic Artist: Andrea Heuston (Artitudes Layout and Design)
Editing Manager: Lynette Skinner
Editor: Jennifer Kerns (S&T Onsite)
Copy Editor: Shari G. Smith (R & S Consulting)

Online Program Manager: Arlo Emerson (Aditi)
Production Support: Irene Barnett (Barnett Communications)
Manufacturing Manager: Bo Galford
Manufacturing Support: Mimi Dukes (S&T Onsite)
Development Services: Kimber Dodge
Lead Product Manager: Mary Larson
Group Product Manager: Robert Stewart


Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution iii


Instructor Notes Module 12: Integrating Collaboration
Data Objects Within an Outlook 2000 Solution
This module presents Collaboration Data Objects (CDO) as a tool for building
collaborative applications within Microsoft
®
Outlook
®
2000. At the end of this
module, students will be able to determine when CDO is an appropriate
development tool. They will be able to distinguish among the CDO Library, the
CDO Rendering Library, and the CDO for NTS Library (Collaboration Data
Objects for Windows NT
®
Server), and determine when it is appropriate to use
each library. They will be able to use the CDO libraries to enhance the
performance of their applications and to perform programming tasks that are
not available by using the Outlook object model.
Materials and Preparation

This section provides you with the materials and preparation needed to teach
this module.
Materials
To teach this module, you need the following materials:

Microsoft PowerPoint
®
file 1593a_12.ppt

Module 12, “Integrating Collaboration Data Objects within an Outlook 2000
Solution”

Preparation
To prepare for this module, you should:

Read all the materials for this module.

Read the instructor notes and margin notes for the module.

Complete the lab.

Rehearse the demonstrations.

Presentation:
90 Minutes

Lab:
45 Minutes
iv Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution



Module Strategy
Use the following strategy to present this module:

Introduction to CDO
Provide an overview of CDO technology. Explain when it is appropriate to
use CDO rather than the Outlook object library. Explain the functionality
and uses of the CDO Library, CDO Rendering Library, and CDO for NTS
Library. Compare the capabilities of the CDO libraries. Explain how to
determine which CDO library to use for particular programming tasks.
Describe how to install the CDO Library and the CDO Rendering Library.

Using the CDO Library in Collaborative Applications
Provide an overview of the CDO Library hierarchy and a summary of the
CDO Library object functions. Compare the most commonly used objects of
the CDO library with their counterparts in the Outlook object library.
Explain how to create a Session object both from within Outlook 2000 and
with dynamic profiles.

Working with Messages and Message Properties
Explain how to select recipients from an address book. Explain how to filter
and find messages in a folder. Explain how to access hidden messages in a
folder. Explain how to retrieve values by using the Fields collection.

Working with the CDO Object Model
Explain how to create a new address book entry. Describe how to return
free/busy information and organize a meeting by using CDO. Describe how
to organize a meeting, access the Organizational Forms Library, and.
Explain how to avoid the common RootFolder problem in a Microsoft
Windows NT service. Demonstrate the use of CDO with the Favorites

folder.

Using the CDO Rendering Library in Collaborative Applications
Provide an overview of the CDO Rendering Library object hierarchy and
the rendering process. Explain how to display a ContainerRenderer object
within a folder home page.

Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution 1


Overview

Introduction to CDO

Using the CDO Library in Collaborative Applications

Working with Messages and Message Properties

Working with the CDO Object Model

Using the CDO Rendering Library in Collaborative
Applications


At the end of this module, you will be able to:

Determine when Microsoft
®
Collaboration Data Objects (CDO) is an
appropriate technology for creating collaborative applications.


Distinguish between the CDO Library, the CDO Rendering Library, and the
CDO for NTS Library (Collaboration Data Objects for Windows NT
®

Server), and determine when it is appropriate to use each library.

Use the CDO libraries to filter messages in a folder, to access hidden
messages, and to retrieve values from messages by using the Fields
collection.

Use the CDO libraries to enhance the performance of your applications and
to perform programming tasks that are not available by using the Microsoft
Outlook
®
object model.

Use the CDO Rendering Library in your collaborative application.

Slide Objective
To provide an overview of
the module topics and
objectives.
Lead-in
In this module, you will learn
about using CDO as a tool
for building collaborative
applications.
2 Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution







Introduction to CDO

Overview of CDO Technology

Determining When to Use CDO

Functionality and Use of CDO Libraries

Comparison of CDO Libraries

Determining Which CDO Library to Use

Installing the CDO and CDO Rendering Libraries


CDO is a technology that enables you to build messaging and collaborative
applications that make use of the information and capabilities of Microsoft
Exchange Server 5.5 Service Pack 1.
Slide Objective
To outline this topic.
Lead-in
It is important to know what
CDO is, what functionality it
can provide, and to
recognize its common

components.
Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution 3


Overview of CDO Technology

Function of CDO

Consists of a library of objects, properties, and methods

Programming interface to MAPI

Use in conjunction with the Outlook object model

Versions of CDO

Version 1.0: (previously called OLE Messaging)

Version 1.1: (previously called Active Messaging)

Version 1.21: (current version; available with
Outlook 2000 and Exchange Server 5.5 Service Pack 1)


The primary functions and versions of CDO are described in the following text.
Function of CDO
CDO is a library of objects, properties, and methods that provide a
programming interface to MAPI. As an interface, CDO simplifies many of the
programming tasks associated with the development of collaborative
applications by providing programmatic access to Exchange Server

information.
You can use CDO in conjunction with the Outlook object model in
collaborative applications based on Outlook 2000 and Exchange Server. Within
both applications, you can accomplish many functions of CDO by using the
Outlook object model. However, CDO provides capabilities beyond those
exposed by the Outlook object model. In addition, there are some cases in
which using CDO, rather than equivalent functions of the Outlook object
model, will result in better performance.
Versions of CDO
Different versions of CDO are recognized by different names. It is useful to be
aware of the previous versions as many Knowledge Base articles and other
technical publications make reference to the previous version names. These
articles can contain content that is still valid for the current version of CDO.

Version 1.0. This version was called OLE Messaging.

Version 1.1. This version was called Active Messaging.

Version 1.21. The current version, CDO 1.21, is available with
Outlook 2000 and with Exchange Server 5.5 Service Pack 1.

Slide Objective
To list the versions of CDO.
Lead-in
MAPI is exposed through
the interfaces of CDO.
4 Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution


Determining When to Use CDO


Using CDO to Access Advanced Features or Information

CDO is used to access information and features that are
not available by using the Outlook object model

For example, use CDO to access a MAPI field that is not
available by using the Outlook object model

Using CDO to Improve Performance

CDO is an in-process .dll and supports less functionality
on each object than Outlook 2000

For example, use CDO to iterate quickly through a large
collection of messages


There are two main reasons for using CDO within an application that is based
on Outlook 2000.
Using CDO to Access Advanced Features or Information
There are many cases in which you can use CDO to access information and
features that are not available by using the Outlook object model. For example,
you can use CDO to access a MAPI field that is not available by using the
Outlook object model. CDO provides a Fields collection that enables a MAPI
field value to be returned by passing the MAPI field tag to the Fields collection.
As another example, CDO provides an Address dialog box in which users can
select recipients from the available address books and have the selected
recipients returned as a Recipients collection. To provide the same
functionality by using the Outlook object model, you would have to create and

program a custom dialog box.
Using CDO to Improve Performance
There are many cases in which you can use a function of CDO, rather than a
similar function of the Outlook object model, to improve the performance of
that function. For example, if your application needs to iterate through a large
collection of messages (and it is not possible to use the SetColumns method
available to Outlook 2000) the application will iterate more quickly if you use
CDO rather than Outlook 2000.
Slide Objective
To describe the situations
when CDO should be used
in place of other
technologies.
Lead-in
Use CDO when you need to
access information that is
not exposed by the Outlook
object model, or when you
need to improve
performance.
Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution 5


Functionality and Use of CDO Libraries

CDO Library

Exposes the most common programmable messaging
objects of MAPI


CDO Rendering Library

Enables you to display information from Exchange
Server in a browser by using HTML

CDO for NTS Library

A separate library that is not used to access information
from Exchange Server

Useful for performing bulk mailing operations without
authentication


CDO includes two libraries—the CDO Library and the CDO Rendering
Library. A third library—the CDO for NTS Library—is also available.
CDO Library
The CDO Library (Cdo.dll) implements the most common programmable
messaging objects of MAPI and exposes them to you. These objects include
folders, messages, recipient addresses, attachments, and other messaging
components. This functionality makes it easier for the developer to create,
maintain, and debug messaging code.
CDO Rendering Library
The CDO Rendering Library (Cdohtml.dll) also exposes programmable
messaging objects and other messaging components. This library enables you to
display information from Exchange Server in the browser by using Hypertext
Markup Language (HTML).
Although the CDO Rendering Library and the CDO Library are separate, they
are complementary. Specifically, the CDO Rendering Library generates HTML
output from CDO Library objects and properties over the Internet. Because the

CDO Rendering Library works with Microsoft Internet Information Server to
generate HTML output, the corresponding .dll file is located on the server and
not on the client computer.
Slide Objective
To list and describe the
three CDO libraries.
Lead-in
CDO provides three
different libraries that you
can use depending on the
requirements of your
application.
6 Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution


CDO for NTS Library
The CDO for NTS Library (Cdonts.dll) is separate from the CDO and CDO
Rendering libraries. The CDO for NTS Library is intended as a streamlined
alternative for a frequently used subset of these tasks. It operates independently
of the other two libraries. It is not used to access information from Exchange
Server, but it is useful for performing bulk mailing operations without
authentication.
The CDO for NTS Library is functionally compatible with a subset of the CDO
Library version 1.2.1, and with a subset of the Active Messaging Library
version 1.1. If an application has been written for either of these libraries, some
modifications are usually required to run it with CDO for NTS. Some features
of Active Messaging, such as fields, folders, and address lists, are unavailable
in CDO for NTS.
Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution 7



Comparison of CDO Libraries
CDO and CDO
Feature CDO for NTS Library Rendering Libraries
Based on MAPI
Supports profiles
Supports authenticated users
Supports address book access
Supports remote server access
Supports SMTP access
Supports calendar access
Supports HTML rendering
Supports MHTML messaging
Supports NewMail object
Can be called from ASP
Compatible with IIS 4.0 and MCIS
Compatible with Active (partially)
Messaging 1.1 applications










✔✔




The two CDO libraries—as well as the CDO for NTS Library—have features
useful to applications in different circumstances. The following table compares
the features of the CDO for NTS Library with those of the CDO Library when
used in conjunction with the CDO Rendering Library.

Feature

CDO for
NTS Library
CDO and CDO
Rendering libraries


Based on MAPI



Supports profiles



Supports authenticated users



Supports address book access




Supports remote server access



Supports Simple Mail Transfer
Protocol (SMTP) access



Supports calendar access



Supports HTML rendering



Supports Mail HTML (MHTML)
messaging



Supports NewMail object



Can be called from Active Server
Pages (ASP)






Compatible with IIS 4.0 and Microsoft
Commercial Internet System (MCIS)



Compatible with Active Messaging 1.1
applications

(partially)



Slide Objective
To compare the features of
the CDO libraries.
Lead-in
Each CDO library supports
different features.
8 Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution


Determining Which CDO Library to Use

When to Use the CDO and CDO Rendering Libraries

For example, if you require authenticated user support or

need to render objects or data into HTML

When to Use the CDO for NTS Library

For example, if you intend to send unauthenticated
e-mail from Web sites

When to Use Either the CDO and CDO Rendering
Libraries or the CDO for NTS Library

For example, if you are developing a server application
or intend to use server-based custom e-mail agents


The following guidelines will help you determine whether to use the CDO and
CDO Rendering libraries or the CDO for NTS Library.
When to Use the CDO and CDO Rendering Libraries
You should use the CDO Library in conjunction with the CDO Rendering
Library if you:

Require authenticated user support.

Need to render objects or data into HTML.

Need to access a personal calendar store.

Intend to access multiple remote computer running Exchange Server.

Anticipate accessing e-mail from remote sites.


Use server-based custom mail agents.

Require automatic load balancing of outgoing e-mail.

Are primarily upgrading an existing CDO 1.2.1 or Active Messaging 1.1
application.

Are developing a client application.

Need to filter or sort messages.

Require support for multiple address book and message store providers.

Are developing a three-tier, Web-based, e-mail application.

Slide Objective
To describe some situations
in which it is appropriate to
use each of the CDO
libraries.
Lead-in
Compare the needs of your
application to the following
guidelines when determining
which CDO library to use.
Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution 9


When to Use the CDO for NTS Library
You should use CDO for NTS if you:


Require support for MHTML.

Anticipate heavy automated generation of outgoing e-mail.

Intend to send unauthenticated e-mail from Web sites.

Use server-based replication of messages.

Anticipate using e-mail for server-based notifications.

When to Use Either the CDO and CDO Rendering
Libraries or the CDO for NTS Library
You can use either the CDO and CDO Rendering libraries or CDO for NTS
Library if you:

Are developing a server application.

Intend to use server-based custom e-mail agents.

10 Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution


Installing the CDO and CDO Rendering Libraries

Installing the CDO Library

Install with a custom installation of Outlook 2000

Install after Outlook 2000 is installed


Install if Office 2000 is being deployed within an
organization

Installing the CDO Rendering Library

Automatically installed by the Exchange Server Setup
program


The CDO Library and CDO Rendering Library are installed in different ways.
Installing the CDO Library
How you install the CDO Library will depend on whether Outlook 2000 is
already installed, and whether Office 2000 is being deployed within your
organization.

CDO Library version 1.21 is installed automatically with Microsoft
Outlook 98 and Microsoft Exchange Server Service Pack 1. CDO Library
(version 1.2) is installed with Exchange Server 5.5 when Active Server
components are selected. No CDO libraries are installed with Microsoft
Outlook 97.

Installing the CDO Library with a Custom Installation of Outlook 2000
A standard installation of Outlook 2000 will not include the CDO Library
(version 1.21). When you install Outlook 2000, you can select a custom
installation and specify that the CDO Library be installed.
Slide Objective
To list the different ways to
install the CDO Library and
the CDO Rendering Library.

Lead-in
The CDO Library is installed
with Microsoft Office. The
version of Office and how
you install it dictates the
manner in which the CDO
Library is installed.
Note
Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution 11


Installing the CDO Library After Outlook 2000 Is Installed
To install the CDO Library if Outlook 2000 is already installed:
1. Click Start, point to Settings, and then click Control Panel.
Control Panel appears.
2. Double-click the Add/Remove Programs icon.
The Add/Remove Programs Properties dialog box appears.
3. In the list of available applications, click Microsoft Office.
4. Click Add/Remove.
After a pause, the Microsoft Office 2000 Maintenance Mode dialog box
appears.
5. Click Add or Remove Features.
The Update Features tree view appears.
6. Expand Microsoft Outlook for Windows, click Collaboration Data
Objects, and then click Run from My Computer.
7. Click Update Now.
After a pause, an alert box informs you that the installation was successful.
8. In the alert box, click OK.
9. To close the Add/Remove Programs Properties dialog box, click OK.


Installing the CDO Library If Office 2000 Is Being Deployed Within an
Organization
If Office 2000 is being deployed within an organization, you can use the
Custom Installation Wizard to generate a transform file (.mst), which instructs
the Microsoft Windows
®
Installer to install CDO during installation.
Installing the CDO Rendering Library
The CDO Rendering Library is automatically installed by the Exchange Server
Setup program when Exchange Server is installed.

To expose content to the Internet by using CDO requires a computer
running Internet Information Server to work with the CDO libraries. However,
the CDO Library can be used alone on the client (or on the server) as a scripting
library.

Note
12 Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution






Using the CDO Library in Collaborative Applications

CDO Object Hierarchy

Summary of CDO Object Functions


Comparison of CDO and Outlook Objects

Creating a Session Object

Creating Session Objects with Dynamic Profiles


The objects in the CDO Library provide the foundation for collaborative
development. The Session object is the primary object that you will use when
developing applications that use CDO. Once you create a Session object by
using the profile of the current user or by creating a dynamic profile, you can
begin working with messages, access the Address Book, and so on. Before
working with the Session object, however, it is important to review the objects
that make up the CDO object hierarchy and how these objects relate to the
Session object. It is also important to see how these objects relate to the
Outlook object model, so that you can choose the best technology given the
requirements of your application, or apply some of what you already know
about one technology to the other.
Slide Objective
To outline this topic.
Lead-in
The Session object is the
foundation of the CDO
object hierarchy.
Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution 13


CDO Object Hierarchy
Folder (Inbox or Outbox)
Folders collection

Messages collection
AppointmentItem
RecurrencePattern
GroupHeader
MeetingItem
Message
Attachments collection
Attachment
AddressLists collection
InfoStores collection
Object and collection
Object only
Session
Object only
with Fields Collection
Recipients collection
Recipient
AddressEntry
MessageFilter
Folder
InfoStore
AddressList
AddressEntries collection
AddressEntry
AddressEntryFilter


The Session object is the topmost object and contains all other objects and
collections in the CDO object hierarchy. The AddressLists and InfoStores
collections are the immediate child objects. Within the InfoStores collection,

the Messages collection, used in nearly all CDO applications, is an immediate
child of the Folders collection.
Although the Fields collection appears on many objects within the CDO object
model, the content of this collection is different for each object. The Fields
collection of a Message object, for example, enables you to access the MAPI
fields within that message. The Fields collection on an InfoStore object
enables you to access the MAPI fields that are linked to that information store.
Slide Objective
To present the hierarchy of
the CDO object library.
Lead-in
It is important to have an
understanding of the CDO
object hierarchy structure.
14 Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution


Summary of CDO Object Functions

Frequently Used CDO Objects and Collections

Session object

AddressLists collection

InfoStores collection

Folder object

Messages collection


Fields collection


The objects and collections in the CDO Library enable you to create
collaborative applications.
The following table lists and describes the uses of the most frequently used
CDO objects and collections.
Name Typical uses

Session object Use the Logon method of the Session object to start a
session with Exchange Server for a user. Use properties
such as Inbox, Outbox, InfoStores, and AddressLists, to
access those objects. Access CurrentUser to return an
AddressEntry object referring to the active user.
AddressLists collection Enables you to traverse all the existing MAPI address
books.
InfoStores collection Enables you to access public folders and personal folder
store (.pst) files.
Folder object The Folder object is an immediate child of the Session
object and is only used to gain access to the Inbox or
Outbox. It has as an immediate child object: the Folders
collection.
Slide Objective
To list the most frequently
used CDO objects and
collections.
Lead-in
It is important to understand
the function of the objects in

the CDO Library.
Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution 15


(continued)
Name Typical uses

Messages collection This collection is a child of a Folder object, which is a
child object of the Folders collection. The Messages
collection contains Message objects, AppointmentItem
objects, and MeetingItem objects. This collection is used
to get, create, delete, and sort messages, appointments, and
meeting items.
Fields collection This collection provides access to the raw MAPI fields
associated with the parent item. The Fields collection is
one of the most powerful features of CDO because it
enables you to easily access information within an item that
has not necessarily been brought through to the item as a
property.

16 Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution


Comparison of CDO and Outlook Objects
CDO Object Outlook Object
InfoStore
Folder
Messages
AddressList
Within CDO, you can use the Fields

collection on this object.
AddressEntry
Within CDO, you can use the Fields
collection on this object.
Although it is not a direct match, the Outlook
2000 NameSpace object is the closest
match to the purpose of the CDO Session
object.
No corresponding Outlook 2000 object.
MAPIFolder
Items
UserProperties
This collection within Outlook 2000 enables
you to access user-defined fields, but not all
MAPI fields as the CDO Fields collection does.
Session
Fields
AddressList
AddressEntry


As a collaborative developer, you need to be aware of both CDO Library and
the Outlook object library. The following table will help you understand the
similarities and differences between the two object libraries, as it compares
some of the objects in the CDO Library to some of the objects of the Outlook
object model.
CDO object Outlook object

Session Although it is not a direct match, the
Outlook 2000 NameSpace object is the closest

match to the purpose of the CDO Session
object.
InfoStore No corresponding Outlook 2000 object.
Folder MAPIFolder
Messages Items
Fields UserProperties
This collection within Outlook 2000 enables
you to access user-defined fields, but not all
MAPI fields as the CDO Fields collection does.
AddressList
Within CDO, you can use the Fields
collection on this object.
AddressList
AddressEntry
Within CDO, you can use the Fields
collection on this object.
AddressEntry

Slide Objective
To show the similarities and
differences between CDO
and Outlook objects.
Lead-in
When deciding to use CDO
or Outlook 2000, it is useful
to have a clear
understanding of the
similarities and differences
between the two object
models.

Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution 17


Creating a Session Object

Creating a Session Object from Visual Basic

Creating a Session Object from VBScript
Dim cdoSession As MAPI.Session
Set cdoSession = New MAPI.Session
cdoSession.Logon showDialog:=False, newSession:=False
Dim cdoSession As MAPI.Session
Set cdoSession = New MAPI.Session
cdoSession.Logon showDialog:=False, newSession:=False


To create a new CDO Session object, you first create a new instance of the
Session object and then use the Logon method to log the Session object onto
the computer running Exchange Server.
The Logon method of the CDO Session object enables you to pass seven
optional parameters as shown in the following syntax.
objSession.Logon([ProfileName], [ProfilePassword], [ShowDialog],
[NewSession], [ParentWindow], [NoMail], [ProfileInfo])

For more information on the Logon method, search for “CDO Logon
Method” in the Microsoft MSDN

Library for Microsoft Office 2000
Developer.


Creating a Session Object from Visual Basic
If you are using Microsoft Visual Basic
®
, you should first set a reference to the
Microsoft CDO 1.21 Library. Early binding distinguishes a MAPI session from
other types of sessions available to a Visual Basic program through other object
libraries.
To prevent the user from being prompted for a profile, you can instruct the
Session object to use the same MAPI session that was started by the
Outlook 2000 client. The following Visual Basic example demonstrates how to
log on to the CDO session without prompting the user for a profile.
Dim cdoSession As MAPI.Session
Set cdoSession = New MAPI.Session
cdoSession.Logon showDialog:=False, newSession:=False

Slide Objective
To show how to create a
new Session object and
then use the Logon
method.
Lead-in
Once you have created a
new Session object, you
can use the Logon method
to log the Session object on
to the Exchange Server.
Note
18 Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution



In the previous example, setting the showDialog parameter to False prevents
CDO from prompting the user for a profile. Setting the newSession parameter to
False instructs CDO to use an existing MAPI session.

An error will occur if there is no active MAPI session when the previous
code sample runs. To avoid this error, ensure that Outlook 2000 is running.

Creating a Session Object from VBScript
To create an instance of the Session object from within an Outlook 2000 form,
you can use the CreateObject method of the Outlook Application object. You
must then log on the CDO Session object without prompting the user for input.
The following example shows how to create an instance of CDO in an
Outlook 2000 form so that the unique functionality of CDO can be taken
advantage of in the Outlook 2000 environment.

' GetSession.oft
Sub cmdStartSession_click()

' This procedure shows automating CDO from Outlook

On Error Resume Next

Set cdoSession = Item.Application.CreateObject("MAPI.Session")

cdoSession.Logon "", "", False, False, 0
MsgBox cdoSession.CurrentUser.Name

cdoSession.Logoff
Set cdoSession = Nothing


End Sub

Note
Delivery Tip
The code for this procedure
can be found at
\Studntcd\Demo\Module12\
GetSession.oft.
Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution 19


Creating Session Objects with Dynamic Profiles
Sub DynSession(strServer, strMailbox)
Dim cdoSession
Dim strProfileInfo
' Construct the profile from server and mailbox name
strProfileInfo = strServer + vbLF + strMailbox
Set cdoSession = CreateObject("MAPI.Session")
cdoSession.Logon "", "", False, True, 0, True, _
strProfileInfo
End Sub
Sub DynSession(strServer, strMailbox)
Dim cdoSession
Dim strProfileInfo
' Construct the profile from server and mailbox name
strProfileInfo = strServer + vbLF + strMailbox
Set cdoSession = CreateObject("MAPI.Session")
cdoSession.Logon "", "", False, True, 0, True, _
strProfileInfo
End Sub


Using VBScript to Create a Session Object with a
Dynamic Profile


CDO supports the creation of Session objects that use dynamic profiles. This is
useful for most new users of client-side applications who have a MAPI user
profile stored locally, but have no user profile stored for server-based
applications. This feature is also useful in applications that are Web-based or
are accessed by using roaming user profiles.
Using VBScript to Create a Session Object with a
Dynamic Profile
The following VBScript example demonstrates the dynamic creation of a
profile.
Sub DynSession(strServer, strMailbox)
Dim cdoSession
Dim strProfileInfo

' Construct the profile from server and mailbox name
strProfileInfo = strServer + vbLF + strMailbox

Set cdoSession = CreateObject("MAPI.Session")
cdoSession.Logon "", "", False, True, 0, True, _
strProfileInfo

End Sub

Slide Objective
To show the dynamic
creation of a profile.

Lead-in
Unlike MAPI, CDO supports
the creation of Session
objects that use dynamic
profiles.
20 Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution






Working with Messages and Message Properties

Selecting Recipients from the Address Book

Filtering Messages in a Folder

Accessing Hidden Messages

Retrieving Values by Using the Fields Collection


You can use the objects in the CDO Library to perform a variety of tasks with
messages and message properties. In some cases, you can only perform these
tasks by using CDO. For example, CDO enables you to display an Address
Book dialog so that users can select recipients. You can also use CDO to access
hidden messages and MAPI properties that are not available when using other
technologies, such as the Outlook object model.
Slide Objective

To outline this topic.
Lead-in
You can use the CDO
objects to work with
messages on an Exchange
Server.
Module 12: Integrating Collaboration Data Objects Within an Outlook 2000 Solution 21


Selecting Recipients from the Address Book

Displaying an Address Book with One Button Enabled

Displaying an Address Book with All Buttons Enabled
On Error Resume Next
Dim cdoRecips ' MAPI.Recipients
Set cdoRecips = _
cdoSession.AddressBook(, "To Only", , , 1, "Select To", , , 0)
If Err.Number <> 0 Then
'No Users selected
Err.Clear
End If
On Error Resume Next
Dim cdoRecips ' MAPI.Recipients
Set cdoRecips = _
cdoSession.AddressBook(, "To Only", , , 1, "Select To", , , 0)
If Err.Number <> 0 Then
'No Users selected
Err.Clear
End If

On Error Resume Next
Dim cdoRecips ' MAPI.Recipients
Set cdoRecips = oSession.AddressBook(, "All Buttons", , , 3, _
"Select To", "Select CC", "Select BCC", 0)
If Err.Number <> 0 Then
'No users selected
Err.Clear
End If
On Error Resume Next
Dim cdoRecips ' MAPI.Recipients
Set cdoRecips = oSession.AddressBook(, "All Buttons", , , 3, _
"Select To", "Select CC", "Select BCC", 0)
If Err.Number <> 0 Then
'No users selected
Err.Clear
End If


Outlook 2000 does not provide a way to prompt users to select an entry from an
address book. However, you can accomplish this by using the CDO
AddressBook method.
Using the AddressBook Method
The AddressBook method enables you to display a customized modal dialog
box that prompts users to select specific entries from an address book.
The syntax for the AddressBook method is as follows:
objSession.AddressBook( [recipients] [, title] [, oneAddress]
[, forceResolution] [, recipLists] [, toLabel] [, ccLabel] [, bccLabel]
[, parentWindow ] )
This method returns a Recipients collection that contains the entries selected by
the user. If the user does not select any entries, the AddressBook method

returns Nothing.
The parameters of the AddressBook method enable you to customize the user
interface of the address book. They also allow you to force users to resolve any
ambiguous names they type.
Slide Objective
To show examples that use
CDO to display the Address
Book dialog box in
Outlook 2000.
Lead-in
You can use the
AddressBook method of
the CDO Session object to
display the Outlook 2000
Address Book dialog box to
users.

×