Working with Tasks: The TaskItem Object

[Previous] [Next]

The Recipients collection is available only to a subset of the Outlook items. This subset consists of the JournalItem, MailItem, AppointmentItem, MeetingItem, TaskRequestItem, and the TaskItem objects. The collection contains Recipient objects that correspond to the names that are in the To, CC, or BCC properties of an item. The following section describes some of the methods and properties of the Recipients collection.

Recipients Collection Properties

The most frequently used property on the Recipients collection is the Count property. This property returns the total number of Recipient objects in the collection.

Recipients Collection Methods

There are a number of methods for the Recipients collection. The most commonly used methods are described next.

Add Method

The Add method takes as its parameter a string that corresponds to the display name or full e-mail address of the user who will be receiving the item. This method returns the new recipient as a Recipient object. The following example shows you the types of strings you can pass in as parameters to the Add method:

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oInbox = oNS.GetDefaultFolder(6)         set oItem = oInbox.Items.Add("IPM.Note")         set newrecip = oItem.Recipients.Add("Michael")         set newrecip1 = oItem.Recipients.Add("thomriz@microsoft.com")         oItem.Display     End Sub 

ResolveAll Method

The ResolveAll method tries to resolve all the recipients in the collection against the contents of the address book. This method returns True if all the recipients are resolved and False if some of the recipients did not resolve correctly. The following code sample calls the ResolveAll method. If some recipients did not resolve, the code displays the item; otherwise the code sends the item.

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oInbox = oNS.GetDefaultFolder(6)         set oItem = oInbox.Items.Add("IPM.Note")         set newrecip = oItem.Recipients.Add("Michael")         set newrecip1 = oItem.Recipients.Add("Mary Ellen")         if not oItem.Recipients.ResolveAll then             msgbox "Some recipients did not resolve."             oItem.Display         else             oItem.Send         end if     End Sub 

Recipient Object

The Recipient object corresponds to a user who is addressed on an Outlook item that can be e-mailed. Recipient objects make up the Recipients collection. Many of the methods and properties for this object overlap with the AddressEntry object.

Recipient Object Properties

The following section describes some of the properties you can use on the Recipient object.

Type Property

The Type property corresponds to the role of the user in the current Recipient object. The value of this property depends on the type of Outlook item that you are querying the property from. For example, in a MailItem, the Type property has four possible values: olOriginator (0), olTo (1), olCC (2), and olBCC (3). In a MeetingItem, the Type property can have the following values: olOrganizer (0), olRequired (1), olOptional (2), olResource (3). The following code shows you how to use the Type property:

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oInbox = oNS.GetDefaultFolder(6)         set oItem = oInbox.Items.Find("[MessageClass]='IPM.Note'")         For each oRecip in oItem.Recipients             txtMessage = "Recipient Name: " & oRecip.Name & chr(13)             Select Case oRecip.Type                 Case 0                     txtType = "Originator"                 Case 1                     txtType = "To"                 Case 2                     txtType = "CC"                 Case 3                     txtType = "BCC"             End Select             txtMessage = txtMessage & "Type: " & txtType             msgbox txtMessage         next         oItem.Display     End Sub 

Recipient Object Methods

The Recipient object contains two methods that you should understand. These are described in the next two sections.

FreeBusy Method

The FreeBusy method is exactly the same as the GetFreeBusy method of the AddressEntry object except for the objects that they are called from: FreeBusy uses the AddressEntry object, and GetFreeBusy uses the Recipient object. (Refer to the section earlier in the supplement describing the AddressEntry object for the specifics of the FreeBusy method.) The following code shows using both methods to return the free/busy information for the same user:

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oInbox = oNS.GetDefaultFolder(6)         set oItem = oInbox.Items.Add("IPM.Note")         set oRecip = oItem.Recipients.Add("Thomas Rizzo (Exchange)")         set oALGAL = oNS.AddressLists("Global Address List")         set oALGALEntries = oALGAL.AddressEntries         set oEntry = oALPABEntries("Thomas Rizzo (Exchange)")         oFBRecip = oRecip.FreeBusy(#5/20/98#, 30)         msgbox oFBRecip         oFBEntry = oEntry.GetFreeBusy(#5/20/98#, 30)         msgbox oFBEntry     End Sub 



Programming Microsoft Outlook and Microsoft Exchange
Programming Microsoft Outlook and Microsoft Exchange, Second Edition (DV-MPS Programming)
ISBN: 0735610193
EAN: 2147483647
Year: 2000
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net