Events in the Outlook Object Model
Understanding the events in the Outlook object model is critical because this is often the primary way that your code is run. This chapter covers many of the events in the Outlook object model, when they are raised, and the type of code you might associate with these events.
Outlook associates the same set of events with all the Outlook item object types listed in Table 10-1. In this chapter, we will refer to Item events, but there is no Item object per se in the Outlook object model. Instead, you will find the same set of Item events (defined by ItemEvents_10_Event interface) on each of the 15 Outlook object model objects listed in Table 10-1.
Object |
Description |
---|---|
AppointmentItem |
An appointment item typically found in the Calendar folder. |
ContactItem |
A contact item typically found in the Contacts folder. |
DistListItem |
A distribution list typically found in the Contacts folder. |
DocumentItem |
A document that you have added to an Outlook folder by dragging and dropping it from the file system into the Outlook folder. |
JournalItem |
A journal entry typically found in the Journal folder. |
MailItem |
A mail message typically found in the Inbox folder. |
MeetingItem |
A meeting request typically found in the Inbox folder. |
NoteItem |
A note typically found in the Notes folder. |
PostItem |
A post in an Outlook folder. |
RemoteItem |
A mail message that has not yet been fully retrieved from the server but has the subject of the message, the received date and time, the sender, the size of the message, and the first 256 characters of the message body. |
ReportItem |
A mail delivery report such as a report when mail delivery failed typically found in Outlook's Inbox folder. |
TaskItem |
A task typically found in the Tasks folder. |
TaskRequestAcceptItem |
A response to a TaskRequestItem typically found in the Inbox folder. |
TaskRequestDeclineItem |
A response to a TaskRequestItem typically found in the Inbox folder. |
TaskRequestItem |
A task request sent to another user typically found in the Inbox folder. |
TaskRequestUpdateItem |
An update to a TaskRequestItem typically found in the Inbox folder. |
Why Are There Multiple Event Interfaces?
When you work with the Outlook object model, you will quickly notice multiple public interfaces, classes, and delegates associated with events:
- ApplicationEvents interface
- ApplicationEvents_Event interface
- ApplicationEvents_* delegates
- ApplicationEvents_SinkHelper class
- ApplicationEvents_10 interface
- ApplicationsEvents_10_Event interface
- ApplicationEvents_10_* delegates
- ApplicationEvents_10_SinkHelper class
- ApplicationEvents_11 interface
- ApplicationsEvents_11_Event interface
- ApplicationEvents_11_* delegates
- ApplicationEvents_11_SinkHelper class
- ExplorerEvents interface
- ExplorerEvents_Event interface
- ExplorerEvents_* delegates
- ExplorerEvents_SinkHelper class
- ExplorerEvents_10 interface
- ExplorerEvents_10_Event interface
- ExplorerEvents_10_* delegates
- ExplorerEvents10_SinkHelper class
- ExplorersEvents interface
- ExplorersEvents_Event interface
- ExplorersEvents_* delegates
- ExplorersEvents_SinkHelper class
- FoldersEvents interface
- FoldersEvents_Event interface
- FoldersEvents_* delegates
- FoldersEvents_SinkHelper class
- InspectorEvents interface
- InspectorEvents_Event interface
- InspectorEvents_* delegates
- InspectorEvents_SinkHelper class
- InspectorEvents_10 interface
- InspectorEvents_10_Event interface
- InspectorEvents_10_* delegates
- InspectorEvents_10_SinkHelper class
- ItemEvents interface
- ItemEvents_Event interface
- ItemEvents_* delegates
- ItemEvents_SinkHelper class
- ItemEvents_10 interface
- ItemEvents_10_Event interface
- ItemEvents_10_* delegates
- ItemEvents_10_SinkHelper class
- ItemsEvents interface
- ItemsEvents_Event interface
- ItemsEvents_* delegates
- ItemsEvents_SinkHelper class
- NameSpaceEvents interface
- NameSpaceEvents_Event interface
- NameSpaceEvents_* delegates
- NameSpaceEvents_SinkHelper class
- OutlookBarGroupsEvents interface
- OutlookBarGroupsEvents_Event interface
- OutlookBarGroupsEvents_* delegates
- OutlookBarGroupsEvents_SinkHelper class
- OutlookBarPaneEvents interface
- OutlookBarPaneEvents_Event interface
- OutlookBarPaneEvents_* delegates
- OutlookBarPaneEvents_SinkHelper class
- OutlookBarShortcutsEvents interface
- OutlookBarShortcutsEvents_Event interface
- OutlookBarShortcutsEvents_* delegates
- OutlookBarShortcutsEvents_SinkHelper class
- ReminderCollectionEvents interface
- ReminderCollectionEvents_Event interface
- ReminderCollectionEvents_* delegates
- ReminderCollectionEvents_SinkHelper class
- ResultsEvents interface
- ResultsEvents_Event interface
- ResultsEvents_* delegates
- ResultsEvents_SinkHelper class
- SyncObjectEvents interface
- SyncObjectEvents_Event interface
- SyncObjectEvents_* delegates
- SyncObjectEvents_SinkHelper class
- ViewsEvents interface
- ViewsEvents_Event interface
- ViewsEvents_* delegates
- ViewsEvents_SinkHelper class
The only elements from this list that you should ever use in your code are the ones in bold text. The *_Event interfaces in bold should only be used when you have to cast an object to its corresponding event interface because a method name and event name collide. An example of this is the Inspector object, which has both a Close method and a Close event. To disambiguate between the two, you have to cast the Inspector object to InspectorEvents_10_Event when you want to handle the Close event.
Chapter 1, "An Introduction to Office Programming," briefly explains the reason for the other items in this list. However, this explanation only explains the SinkHelper class and why there is both an ObjectEvents interface and an ObjectEvents_Event interface. The reason there are multiple numbered events associated with some objects goes back to the original COM implementation of the Outlook object model.
Outlook's Application, Explorer, Inspector, and Item COM objects have had their event interfaces defined over multiple versions. For example, consider the Application events. Events defined in Outlook XP for the Application object are on the interface named ApplicationEvents_Event. Events that were new in Outlook 2000 are on the interface named ApplicationEvents_10_Events. (Outlook 2000 was known internally at Microsoft as Outlook 10.) ApplicationEvents_10_Events also contains all the events that are in the ApplicationEvents_Event. Events that were new in Outlook 2003 are on the interface named ApplicationEvents_11_Events. (Outlook 2003 was known internally at Microsoft as Outlook 11.) The ApplicationEvents_11_Events interface includes all the events defined in Outlook XP and Outlook 2000. Because ApplicationEvents_11_Events contains all the events defined for Application, this is the only interface you should use for Outlook 2003 development.