Working with Folder Contents: The Items Collection

[Previous] [Next]

Since Outlook supports many item objects such as the PostItem, MailItem, and ContactItem objects, this section will highlight only key methods and properties for these objects. The common properties and methods for all the objects will be discussed after looking at the unique properties and methods for each object. For a full reference for each object type, see the Olform.hlp file on the companion CD.

The PostItem Object

A PostItem object differs from a MailItem object in Outlook in that a MailItem object is e-mailed to another user whereas a PostItem object is posted into a folder. Since the objects are so similar, both have nearly the same methods and properties. This section describes the most common properties and methods you use on a PostItem object.

PostItem Properties

The following section shows only one property for the PostItem object, but there are many properties that you can use in your application.

HTMLBody Property

The HTMLBody property allows you to retrieve or set the HTML string that represents the body of a message. You should use HTML syntax when setting this property. If you do set this property, Outlook automatically changes the EditorType property to olEditorHTML (2). The following code sample shows you how to use the HTMLBody property:

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oInbox = oNS.GetDefaultFolder(6)         set oNewItem = oInbox.Items.Add         oNewItem.HTMLBody = "<h1><B>This is my new Message</b></h1>" & _             "<P><U><I>Please be sure to read it.</I></U>"         oNewItem.Display     End Sub 

PostItem Object Methods

The PostItem object contains only one method that is different from the common methods for all the Outlook item objects: ClearConversationIndex. This method is also implemented for MailItem objects.

ClearConversationIndex Method

The ClearConversationIndex method allows you to clear the conversation thread for the current object. By doing this, the item will no longer appear as a thread in a threaded view. The following code shows you how to use this method:

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oInbox = oNS.GetDefaultFolder(6)         set oItem = oInbox.Items.GetFirst()         oItem.ClearConversationIndex     End Sub 

The MailItem Object

The MailItem object contains a number of methods and properties that are unique across all of the Outlook item objects. The following section describes some of these properties and methods.

MailItem Properties

This section covers some of the main MailItem properties.

Address Properties: To, CC, BCC

With the MailItem object, you can retrieve the address properties of a MailItem object. Each of these properties takes a semicolon-delimited list of users to send new items to. If you are modifying these address properties after receiving an item or opening an existing MailItem object, you should use the Recipients collection. The following code creates a new e-mail message and sends it to a number of users using the address properties:

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oInbox = oNS.GetDefaultFolder(6)         set oItem = oInbox.Items.Add("IPM.Note")         oItem.Subject = "My New Message"         oItem.To = "thomriz@microsoft.com"         oItem.CC = "someone@microsoft.com"         oItem.BCC ="someone@microsoft.com"         oItem.Display     End Sub 

DeferredDeliveryTime Property

The DeferredDeliveryTime property allows you to specify a date when Outlook should deliver a message. This property is useful in applications where you want to create an item but not deliver it until a specified amount of time has passed. For example, suppose you wanted Outlook to generate a mail merge of 10,000 contacts to create an e-mail sales promotion, but you wanted to wait to send all of those e-mails until after work hours so that the e-mails did not bog down the corporate network. You can set this property so that the e-mails are sent out after 5 PM to all 10,000 people. The following code sample shows you how to set this property:

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oInbox = oNS.GetDefaultFolder(6)         set oItem = oInbox.Items.Add("IPM.Note")         oItem.Subject = "My New Message"         oItem.To = "thomriz@microsoft.com"         oItem.DeferredDeliveryTime = #5/20/98 5:00 PM#         oItem.Send     End Sub 

ExpiryTime Property

The ExpiryTime property, which is also available on PostItem and MeetingItem objects, allows you to specify a date when the current item should become invalid and can be deleted. Outlook will display the expired messages as messages with a line through the entire message text. This property is useful in applications where newer information is made available at regular intervals. For example, if you use Outlook to send automated monthly sales reports, you may want to set the ExpiryTime property for your sales reports to be 6 months, because most users will not want to read sales reports that are 6 months old or older. The following code shows you how to set this property so that the item expires after 6 months from the current date. Click the Options button on the message to see the expiration date.

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oInbox = oNS.GetDefaultFolder(6)         set oItem = oInbox.Items.Add("IPM.Note")         oItem.Subject = "Monthly Sales Report"         oItem.To = "thomriz@microsoft.com"         oItem.ExpiryTime = Date + 180         oItem.Display     End Sub 

OriginatorDeliveryReportRequested and ReadReceiptRequested Properties

The OriginatorDeliveryReportRequested and ReadReceiptRequested properties allow your application to request read and delivery receipts for MailItem objects that the applications send. You can have Outlook collate these receipts so that you can display the time the item was delivered and read by the user. The following code sample shows you to how to use these two properties. Click the Options button on the message to see the request for both a read receipt and a delivery receipt for the message.

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oInbox = oNS.GetDefaultFolder(6)         set oItem = oInbox.Items.Add("IPM.Note")         oItem.Subject = "Read and delivery receipts"         oItem.To = "thomriz@microsoft.com"         oItem.OriginatorDeliveryReportRequested = True         oItem.ReadReceiptRequested = True         oItem.Display     End Sub 

VotingOptions and VotingResponse Properties

The VotingOptions and VotingResponse properties allow you to create voting buttons programmatically as well as get or set the voting response of a user. The VotingOptions property takes a delimited string that sets the voting options the user can select. The following code shows you how to use the VotingOptions property. Click the Options button in the e-mail message to see the voting buttons.

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oInbox = oNS.GetDefaultFolder(6)         set oItem = oInbox.Items.Add("IPM.Note")         oItem.Subject = "Voting Buttons for dates for the book promotion"         oItem.To = "thomriz@microsoft.com"         oItem.VotingOptions = "June; July; August"         oItem.Display     End Sub 

MailItem Object Methods

The MailItem object contains methods that allow you to perform the standard operations on an Outlook item such as Move, Copy, or Delete. The MailItem object also contains other methods that allow you to reply or forward existing MailItem objects. The following section describes the interesting methods on the MailItem object.

Send Method

The Send method allows you to send the item to recipients. The following code sample shows you how to use the Send method:

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oInbox = oNS.GetDefaultFolder(6)         set oItem = oInbox.Items.Add("IPM.Note")         oItem.Subject = "Voting Buttons for dates for the book promotion"         oItem.To = "thomriz@microsoft.com"         oItem.VotingOptions = "June; July; August"         oItem.Send     End Sub 

Reply and ReplyAll Methods

The Reply and ReplyAll methods allow your program to reply to items that have been received. These objects will automatically pre-address the item with the correct recipients from the original message. For example, the Reply method automatically adds only the sender to the response, and ReplyAll method adds the sender plus any recipients in the CC property. These methods will return the replies as MailItem objects. The following code shows you how to use these methods:

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oInbox = oNS.GetDefaultFolder(6)         set oItems = oInbox.Items         set oFirst = oItems.Find("[MessageClass]=""IPM.Note""")         set oReply = oFirst.Reply         oReply.Display         msgbox "This is a Reply"         set oSecond = oItems.FindNext         set oReplyAll = oSecond.ReplyAll         oReplyAll.Display         msgbox "This is a ReplyAll"     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