Programming Tasks
Programming Tasks
This section describes some of the common programming tasks you can perform with the Collaboration Data Objects (CDO) Library. The first task your application must complete is to obtain and Logon to a valid Session object as described in Starting a CDO Session. The following table categorizes the described tasks:
The following table summarizes the programming procedures that you must use to perform these tasks. Note that all tasks require a valid
Procedure |
|
1. Access the Folder object’s Folders property to obtain its collection of subfolders. 2. Use the Folders collection’s GetFirst, GetNext, GetPrevious, and GetLast methods to navigate through the subfolders. |
|
1. Create or obtain the Message object that is to include the attachment. 2. Call the Message object’s Attachments collection’s Add method. 3. Call the Message object’s Update or Send method. |
|
1. Obtain a valid AddressEntry object. 2. Update the AddressEntry object’s Name, Type, or Address property. 3. Call the AddressEntry object’s Update method. |
|
Count messages in the Inbox folder that have the Unread property set to True. – Or – Count messages received after a specified time. |
|
1. Obtain the source message that you want to copy. 2. Call the source Message object’s CopyTo method. 3. Call the new Message object’s Update method. |
|
1. Obtain the Session object’s AddressLists collection. 2. Select the AddressList object corresponding to the desired address book container. 3. Obtain the address list’s AddressEntries collection. 4. Call the AddressEntries collection’s Add method. |
|
1. Call the Messages collection’s Add method to create a Message object. 2. Set the Message object’s Text, Subject, and other message properties. 3. Call the message’s Recipients collection’s Add method to add a recipient. – Or – 3. Copy a Recipients collection from another message to the new message’s Recipients property. 4. Set the Recipient object’s Name, Address,or AddressEntry property. 5. Call the Recipient object’s Resolve method to validate the address information. 6. Call the Message object’s Send method. |
|
1. Create or obtain the Folder or Message object that is to have the custom properties. 2. Call the object’s Fields collection’s Add method. |
|
1. Select the message you want to delete. 2. Call the Message object’s Delete method. |
|
1. Access the folder in which you wish to filter the messages. 2. Obtain the MessageFilter object for the folder. 3. Select and set the desired MessageFilter properties to specify the filter. |
|
Use the Microsoft® Visual Basic® On Error Goto statement to add exception-handling code just as you would in any Visual Basic application. |
|
Each dot in a Visual Basic statement directs the CDO Library to create a temporary internal object. Use explicit variables when you reuse messaging objects. |
|
1. Set the Message object’s DeliveryReceipt and/or ReadReceipt properties to True. 2. Call the Message object’s Send method. |
|
1. Obtain the source message that you want to move. 2. Call the source Message object’s MoveTo method. 3. Call the Message object’s Update method at its new location. |
|
1. Obtain a calendar folder from the session. 2. Add an appointment to the calendar folder. 3. Create a Recipients collection for the appointment. 4. Populate the appointment's Recipients collection. 5. Send the appointment to the recipients. |
|
Use a procedure similar toCreating and Sending a Message, where you specify the name of the public folder as the recipient name. – Or – 1. Call the public folder’s Messages collection’s Add method to create a Message object. 2. Set the Message object’s Text, Subject, ConversationSubject, ConversationIndex, TimeSent, TimeReceived,and other message properties. 3. Set the Message object’s Unread, Submitted, and Sent properties to True. 4. Call the Message object’s Send or Update method to post the message. |
|
1. Call the session’s Inbox folder’s GetFirst, GetNext, GetPrevious, and GetLast methods to obtain a Message object. 2. Obtain the Message object’s Text property. |
|
Use the Session object’s GetFolder method to obtain the folder from its known identifier value. – Or – Call the Folders collection’s Get methods to get individual Folder objects, and compare properties of each folder with the desired property values. |
|
Use the Session object’s GetMessage method to obtain the message from its known identifier value. – Or – Call the Messages collection’s Get methods to get individual Message objects, using a message filter to reduce the number of messages searched, and if necessary compare properties of each message with the desired property values. |
|
1. Call the session’s AddressBook method to use the MAPI address book dialog box. 2. Set a Recipients collection object to the Recipients collection returned by the AddressBook method. 3. Use that Recipients collection or copy individual recipients from it. |
|
1. Create or obtain a Session object. 2. Call the Session object’s Logon method. |
|
1. Set the message’s Recipient object’s Address property to a full address. 2. Call the Recipient object’s Resolve method. |
|
Specify a MAPI property tag as the Fields collection’s Item property. |
|
1. Set the message’s ConversationTopic property. 2. Set the message’s ConversationIndex property. 3. Send the message by calling the Send method. – Or – 3. Post the message in the public folder by setting the Submitted property to True. |
|
1. Add a distribution list (DL) to a personal address book (PAB). 2. Add an address entry to a distribution list. 3. Delete an address entry from a distribution list. |
It is important to understand the hierarchy of the CDO Library objects, because the hierarchical relationships between objects determines the correct syntax of Microsoft® Visual Basic® statements. The relative positions of these objects in the hierarchy indicate how the objects appear from left to right in a Visual Basic statement. For more information on the hierarchy, see Object Model.
In the sample code that appears in this guide, individual statements are often broken across several lines. The convention used for this is the statement continuation introduced in Visual Basic version 4.0, which consists of a space followed by the underscore character (_). This sequence is placed at the end of a code line to indicate that the current statement is continued on the next line.