Outlook Object Model Overview
To develop add-ins for Microsoft Office Outlook, you can interact with the objects provided by the Outlook object model. The Outlook object model provides classes that represent items in the user interface. For example, the Microsoft.Office.Interop.Outlook.Application class represents the entire application, the Microsoft.Office.Interop.Outlook.MAPIFolder class represents a folder that contains e-mail messages or other items, and the Microsoft.Office.Interop.Outlook.MailItem class represents an e-mail message.
This topic provides a brief overview of some of the main classes in the Outlook object model. For complete documentation for the Outlook object model, see "Welcome to the Microsoft Office Outlook 2003 VBA Language Reference" (http://go.microsoft.com/fwlink/?linkid=27946). For code examples that demonstrate how to perform common tasks by using the Outlook object model in Microsoft Visual Studio 2005 Tools for the Microsoft Office System (VSTO 2005), see .
Accessing Objects in an Outlook Project
Outlook provides many classes with which you can interact. The following sections briefly describe some of the top-level classes and how they interact with each other. These classes include:
The Microsoft.Office.Interop.Outlook.Application class represents the Outlook application, and it is the highest-level class in the Outlook object model. Some of the most important members of this class include:
The CreateItem method, which you can use to create a new item such as an e-mail message, task, or appointment.
The Explorers property, which you can use to access the windows that display the contents of a folder in the Outlook user interface (UI).
The Inspectors property, which you can use to access the windows that display the contents of a single item, such as an e-mail message or meeting request.
For information about accessing the Microsoft.Office.Interop.Outlook.Application class from Outlook add-ins, see.
Passing Application to Methods and Properties
In add-ins created by using Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System (VSTO 2005 SE), you can pass the
ThisAddIn.Application object to a method or property that requires a Microsoft.Office.Interop.Outlook.Application object.
In add-ins created by using VSTO 2005, you cannot pass the
ThisApplication object to a method or property that requires a Microsoft.Office.Interop.Outlook.Application. This is because
ThisApplication does not derive from Microsoft.Office.Interop.Outlook.Application. However, you can pass the
Application property of an object that you obtain from
ThisApplication, such as a Microsoft.Office.Interop.Outlook.Explorer or Microsoft.Office.Interop.Outlook.Inspector.
The Microsoft.Office.Interop.Outlook.Application that you obtain in this manner is trusted by the Outlook object model guard.
The following code example demonstrates how to use the ActiveExplorer method of the
ThisApplication object, represented by the keyword Me in Visual Basic and this in C#, to get a Microsoft.Office.Interop.Outlook.Application.
The Microsoft.Office.Interop.Outlook.Explorer class represents a window that displays the contents of a folder that contains items such as e-mail messages, tasks, or appointments. The Explorer class includes methods and properties that you can use to modify the window, and events that are raised when the window changes.
To get an Explorer object, do one of the following:
Use the Explorers property of the Microsoft.Office.Tools.Outlook.Application class to access all of the Explorer objects in Outlook.
Use the ActiveExplorer method of the Microsoft.Office.Tools.Outlook.Application class to get the Explorer that currently has focus.
Use the GetExplorer method of the Microsoft.Office.Tools.Interop.MAPIFolder class to get the Explorer for the current folder.
The Microsoft.Office.Interop.Outlook.Inspector class represents a window that displays a single item such as an e-mail message, task, or appointment in the Outlook UI. The Inspector class includes methods and properties that you can use to modify the window, and events that are raised when the window changes.
To get an Inspector object, do one of the following:
Use the Inspectors property of the Microsoft.Office.Tools.Outlook.Application class to access all of the Inspector objects in Outlook.
Use the ActiveInspector method of the Microsoft.Office.Tools.Outlook.Application class to get the Inspector that currently has focus.
Use the GetInspector method of a specific item, such as a Microsoft.Office.Interop.Outlook.MailItem or Microsoft.Office.Interop.Outlook.AppointmentItem, to retrieve the Inspector associated with it.
The Microsoft.Office.Interop.Outlook.MAPIFolder class represents a folder that contains e-mail messages, contacts, tasks, and other items. Outlook provides 16 default MapiFolder objects. The default MapiFolder objects are defined by the Microsoft.Office.Interop.Outlook.OlDefaultFolders enumeration values. For example, OlDefaultFolders.olFolderInbox corresponds to the Inbox folder in Outlook. For an example that shows how to access a default MAPIFolder and create a new MAPIFolder, see.
The Microsoft.Office.Interop.Outlook.MailItem class represents an e-mail message. MailItem objects are usually in folders, such as Inbox, Sent Items, and Outbox. MailItem exposes properties and methods that can be used to create and send e-mail messages. For an example that shows how to create an e-mail message, see.
The Microsoft.Office.Interop.Outlook.AppointmentItem class represents a meeting, a one-time appointment, or a recurring appointment or meeting in the Calendar folder. The AppointmentItem class includes methods that perform actions such as responding to or forwarding meeting requests, and properties that specify meeting details such as the location and time. For an example that shows how to create an appointment, see.
The Microsoft.Office.Interop.Outlook.TaskItem class represents a task to be performed within a specified time frame. TaskItem objects are located in the Tasks folder. To create a task, use the CreateItem method of the Microsoft.Office.Tools.Outlook.Application class, and pass in the value Microsoft.Office.Interop.Outlook.OlItemType.olTaskItem for the parameter.
The Microsoft.Office.Interop.Outlook.ContactItem class represents a contact in the Contacts folder. ContactItem objects contain a variety of contact information for the people they represent, such as street addresses, e-mail addresses, and phone numbers. For an example that shows how to create a new contact, see. For an example that shows how to search for an existing contact, see .