
Accessing Objects in an Outlook Project
Outlook provides many classes with which you can interact. To use the object model effectively, you should be familiar with the following top-level classes:
Application
Explorer
Inspector
MAPIFolder
MailItem
AppointmentItem
TaskItem
ContactItem
Application Class
The 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.
To get an instance of the Application class, use the Application property of the ThisAddin class.
ThisAddIn Class
When you create a new Outlook add-in project, Visual Studio Tools for Office automatically creates a ThisAddIn.vb or ThisAddIn.cs code file in your new project. This code file defines a ThisAddin class that inherits from OutlookAddIn. You can access the members of the OutlookAddIn class by using the keywords Me (in Visual Basic) or this (in C#) within the ThisAddIn class. Code that is outside the ThisAddIn class can access the ThisAddIn object by using the static Globals.ThisAddIn property.
Explorer Class
The 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 Application class to access all of the Explorer objects in Outlook.
Use the ActiveExplorer()()() method of the Application class to get the Explorer that currently has focus.
Use the GetExplorer method of the MAPIFolder class to get the Explorer for the current folder.
Inspector Class
The Inspector class represents a window that displays a single item such as an e-mail message, task, or appointment. 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 Application class to access all of the Inspector objects in Outlook.
Use the ActiveInspector()()() method of the Application class to get the Inspector that currently has focus.
Use the GetInspector method of a specific item, such as a MailItem or AppointmentItem, to retrieve the Inspector that is associated with it.
MAPIFolder Class
The 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 OlDefaultFolders enumeration values. For example,
T:Microsoft.Office.Interop.Outlook.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 How to: Create Custom Folder Items.
MailItem Class
The 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 How to: Create an E-Mail Item.
AppointmentItem Class
The 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 How to: Create a Meeting Request.
TaskItem Class
The 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 Application class, and pass in the value olTaskItem()()() for the parameter.
ContactItem Class
The ContactItemclass 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 How to: Add an Entry to Outlook Contacts. For an example that shows how to search for an existing contact, see How to: Search for a Specific Contact.