Working with the CDO Object Model 29 Using the CDO Rendering Library in Objects Within an Outlook 2000 Solution... Overview Introduction to CDO Using the CDO Library in Collaborative
Trang 1Working with the CDO Object Model 29
Using the CDO Rendering Library in
Objects Within an Outlook 2000 Solution
Trang 2with 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
Trang 3Instructor 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
Trang 4Module 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
Trang 5Overview
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
In this module, you will learn
about using CDO as a tool
for building collaborative
applications
Trang 6Introduction to CDO
Overview of CDO Technology
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
Trang 7Overview 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
Trang 8Determining 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
Trang 9Functionality 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
Trang 10CDO 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
Trang 11Comparison 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
Feature NTS Library CDO for Rendering libraries CDO and CDO
Supports Simple Mail Transfer Protocol (SMTP) access
✔
Supports Mail HTML (MHTML) messaging
✔
Can be called from Active Server Pages (ASP)
To compare the features of
the CDO libraries
Lead-in
Each CDO library supports
different features
Trang 12Determining 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
Compare the needs of your
application to the following
guidelines when determining
which CDO library to use
Trang 13When 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
Trang 14Installing 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
Trang 15Installing 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
Trang 16Using the CDO Library in Collaborative Applications
CDO Object Hierarchy
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
Trang 17CDO 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
Trang 18Summary of CDO Object Functions
Frequently Used CDO Objects and Collections
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
Trang 19(continued)
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
Trang 20Comparison 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
Outlook 2000 NameSpace object is the closest match to the purpose of the CDO Session
object
Folder MAPIFolder Messages Items
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
similarities and differences
between the two object
models
Trang 21Creating a Session Object
Creating a Session Object from Visual Basic
Creating a Session Object from VBScript
Dim cdoSession As MAPI.SessionSet cdoSession = New MAPI.SessioncdoSession.Logon showDialog:=False, newSession:=False
Dim cdoSession As MAPI.SessionSet cdoSession = New MAPI.SessioncdoSession.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
Trang 22In 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
Trang 23Creating Session Objects with Dynamic Profiles
Sub DynSession(strServer, strMailbox)Dim cdoSession
Dim strProfileInfo' Construct the profile from server and mailbox namestrProfileInfo = 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 namestrProfileInfo = 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
Unlike MAPI, CDO supports
the creation of Session
objects that use dynamic
profiles
Trang 24Working with Messages and Message Properties
Selecting Recipients from the Address Book
Filtering Messages in a Folder
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
Trang 25Selecting 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)
cdoSession.AddressBook(, "To Only", , , 1, "Select To", , , 0)
"Select To", "Select CC", "Select BCC", 0)
"Select To", "Select CC", "Select BCC", 0)
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
Trang 26Displaying an Address Book with One Button Enabled
The following example displays an address book with only the To button enabled, the caption of the address book titled To Only, and the text on the To button labeled Select To
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
If a user clicks the Cancel button in the Address Book dialog box, CDO
returns a run-time error Therefore, you must place code in your application to handle this run-time error, as shown in the previous example
Displaying an Address Book with All Buttons Enabled
The following example displays an address book in which all of the address buttons are enabled
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
Note
Trang 27Filtering Messages in a Folder
Set cdoSession = CreateObject ( "MAPI.Session" ) cdoSession.Logon,, False, False ' assume valid session for this example Set cdoInbox = cdoSession.Inbox
If cdoInbox Is Nothing Then MsgBox "Invalid IPM Inbox from session"
Exit Sub End If Set cdoMsgColl = cdoInbox.Messages ' get Inbox's Messages collection ' ( then validate the messages collection before proceeding ) Set cdoMsgFilter = cdoMsgColl.Filter
' ( then validate the message filter before proceeding ) cdoMsgFilter.TimeLast = DateValue ( "07/21/99" )
cdoMsgFilter.Unread = True ' filter for unread messages ' Message filter is now specified; ready for display loop
For Each cdoMess in cdoMsgColl ' performs loop, Sets each cdoMess MsgBox "Message not read: " & cdoMess.Subject
Next End Sub
Set cdoSession = CreateObject ( "MAPI.Session" ) cdoSession.Logon,, False, False ' assume valid session for this example Set cdoInbox = cdoSession.Inbox
If cdoInbox Is Nothing Then MsgBox "Invalid IPM Inbox from session"
Exit Sub End If Set cdoMsgColl = cdoInbox.Messages ' get Inbox's Messages collection ' ( then validate the messages collection before proceeding ) Set cdoMsgFilter = cdoMsgColl.Filter
' ( then validate the message filter before proceeding ) cdoMsgFilter.TimeLast = DateValue ( "07/21/99" )
cdoMsgFilter.Unread = True ' filter for unread messages ' Message filter is now specified; ready for display loop
For Each cdoMess in cdoMsgColl ' performs loop, Sets each cdoMess MsgBox "Message not read: " & cdoMess.Subject
Next End Sub
You can work through each member in a collection of objects to take some action on all its members, such as displaying, sending, or copying the members
Often this process involves a For Each construction or a GetFirst GetNext loop But working through a large collection such as AddressEntries or Messages can be a slow process If you are only interested in certain members
of the collection, your code can make efficient use of a filter
Using Filtering to Limit Members in a Collection
The purpose of filtering is to limit the members of a collection The members are limited based on the values of the properties that you specify for the filter Once a filter has been applied, only those members that satisfy every filter property you have set are processed by your application
Suppose, for example, you want to find all unread messages received before a certain date, and to display the subject of each message You can set the message filter to limit the messages by obtaining the Inbox folder, the
Messages collection of the folder, and the MessageFilter object of the collection Next, set the Unread property of the filter to True and its TimeLast
property to the desired date
Slide Objective
To show an example that
filters messages in a folder
Lead-in
Applying a filter to a
collection of messages or
recipients can make some
operations more efficient
Delivery Tip
The code for the following
procedure can be found at
\Studntcd\Demo\Module12\
FilterMsg.oft
Trang 28The following Visual Basic example displays the Subject property for every
unread message in the Inbox that was received before July 21, 1999
Dim cdoMess ' individual message processed in loop
Set cdoSession = CreateObject ( "MAPI.Session" )
cdoSession.Logon , , False, False ' assume valid session for this example Set cdoInbox = cdoSession.Inbox
If cdoInbox Is Nothing Then
MsgBox "Invalid IPM Inbox from session"
Exit Sub
End If
Set cdoMsgColl = cdoInbox.Messages ' get Inbox's Messages collection
' ( then validate the messages collection before proceeding )
Set cdoMsgFilter = cdoMsgColl.Filter
' ( then validate the message filter before proceeding )
cdoMsgFilter.TimeLast = DateValue ( "07/21/99" )
cdoMsgFilter.Unread = True ' filter for unread messages
' Message filter is now specified; ready for display loop
For Each cdoMess in cdoMsgColl ' performs loop, Sets each cdoMess
MsgBox "Message not read: " & cdoMess.Subject
Next
Trang 29Accessing Hidden Messages
Dim cdoHidden Dim cdoMessage Dim cdoSession Set cdoSession = CreateObject ("MAPI.Session") cdoSession.Logon " ", " " False, False, 0 Set cdoInbox = cdoSesson.Inbox
Set cdoHidden = cdoInbox.HiddenMessages MsgBox " There are " & cdoHidden.Count & " hidden messages "
For i = 1 To cdoHidden.Count Set cdoMessage = cdoHidden.Item(i) MsgBox "Message Type: " & cdoMessage.Type Next
End Sub
Dim cdoHidden Dim cdoMessage Dim cdoSession Set cdoSession = CreateObject ("MAPI.Session") cdoSession.Logon " ", " " False, False, 0 Set cdoInbox = cdoSesson.Inbox
Set cdoHidden = cdoInbox.HiddenMessages MsgBox " There are " & cdoHidden.Count & " hidden messages "
For i = 1 To cdoHidden.Count Set cdoMessage = cdoHidden.Item(i) MsgBox "Message Type: " & cdoMessage.Type Next
End Sub
Using the HiddenMessages Property
Each folder contains hidden messages that are not visible to any of the Outlook 2000 clients and include view definitions, agents, out-of-office templates, and rules stored in a particular folder You may find it useful for your application to access hidden messages within a folder, although you cannot access hidden messages by using the Outlook object model However, in
CDO you can use the HiddenMessages property of the Folder object to return
a collection of hidden messages within a specified folder
that returns a collection of
all hidden messages from
within a folder
Trang 30Using the HiddenMessages Property
The HiddenMessages property of the Folder object returns a Messages
collection that contains all of the hidden messages in the folder You should not modify this collection unless you are sure that the modifications you make will not affect other users You can add new messages to this collection to
implement specific tasks in your applications, for example, you could create a hidden data source for a list box When a user launches your form, the list box would be populated with specific messages from the collection returned by the
HiddenMessages property
The following example displays all of the hidden messages in a folder, along with their message classes and message subjects, if the message subjects exist ' Hidden.oft
Sub cmdHiddenMessage_click()
Dim cdoHidden
Dim cdoMessage
Dim cdoSession
Set cdoSession = CreateObject("MAPI.Session")
cdoSession.Logon "", "", False, False, 0
Set cdoInbox = cdoSession.Inbox
Set cdoHidden = cdoInbox.HiddenMessages
MsgBox "There are " & cdoHidden.Count & " hidden messages."
For i = 1 To cdoHidden.Count
Set cdoMessage = cdoHidden.Item(i)
MsgBox "Message type: " & cdoMessage.Type
Next
End Sub
Delivery Tip
The code for the following
procedure can be found at
\Studntcd\Demo\Module12\
Hidden.oft
Trang 31Retrieving Values by Using the Fields Collection
MAPI Message
&H0037001E Please review…
&H0037001E Please review…
MyCustomProperty Some information
provided through the Fields collection
The Fields collection object contains one or more Field objects Field objects enable you to access MAPI properties on the parent object of the Fields
collection These include the predefined underlying MAPI properties and your own custom user-defined properties
Accessing MAPI Properties
MAPI defines a set of properties with identifiers less than the value &H8000 These are known as unnamed properties because they are accessed by using the MAPI property tag rather than by using a name You can access these MAPI-
defined properties by using the Fields collection All MAPI properties are
accessible except those of the types PT_OBJECT and PT_CLSID
For more information on MAPI-defined property tags and Exchange Server–defined property tags, see the Appendix of Collaboration Data Objects Help (CDO.hlp) that ships with Exchange Server 5.5 Service Pack 1
MAPI to CDO Data Type Conversion
Data types are preserved between MAPI properties and CDO fields, with the exception of MAPI properties of the type PT_BINARY These data types are converted from counted binary in MAPI to character string representation in CDO, where the characters in the string represent the hexadecimal digits of the MAPI property value The string is converted back into counted binary when you write to the field
Slide Objective
To show how the Fields
collection provides access
to the raw MAPI fields
Lead-in
CDO enables you to access
properties that are not
available through the use of
other technologies, such as
the Outlook object model
Note
Trang 32Accessing Custom Properties
You can also extend the properties available through MAPI by defining your own properties These user-defined properties, defined by using a name and automatically assigned an identifier greater than &H8000 by CDO, are called
“named properties.”
MAPI stores all custom properties that represent date and time information by using Greenwich Mean Time CDO converts these properties so that the values appear to the user in local time
Retrieving Values from MAPI or Custom Properties
To uniquely identify a Field object in the Fields collection, use the Field object’s Name or Index property, or the MAPI property tag, as shown in the
following example
Set cdoNamedField1 = cdoFolder.Fields.Item("BalanceDue") Set cdoNamedField2 = cdoMessage.Fields.Item("Keyword") Set cdoIndexedField = cdoMessage.Fields.Item(3)
propTag = &H0E180003 ' propTag = CdoPR_MESSAGE_DOWNLOAD_TIME Set cdoMAPIField = cdoMessage.Fields.Item(propTag)