Share via


Outlook Object Model Overview

To develop add-ins for Microsoft Office Outlook, you can interact with the objects that are provided by the Outlook object model. The Outlook object model provides classes that represent items in the user interface. For example, the Application class represents the entire application, the MAPIFolder class represents a folder that contains e-mail messages or other items, and the 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 the MSDN sections Outlook 2007 Developer Reference and Welcome to the Microsoft Office Outlook 2003 VBA Language Reference.

link to video For a related video demonstration, see How Do I: Use Outlook to Create a Custom Task Report?.

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 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.

Note

To help avoid security warnings when you use properties and methods that are blocked by the Outlook object model guard, get Outlook objects from the ThisAddIn object. For more information, see Specific Security Considerations for Office Solutions.

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:

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:

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.

Using the Outlook Object Model Documentation

For information about the classes you can use in the Outlook object model, see the following sets of documentation:

The first link provides information about the classes and interfaces in the primary interop assembly for Outlook. The other links provide information about the Outlook object model as it is exposed to Visual Basic for Applications (VBA) code. Each set of documentation has advantages and disadvantages for developers who are using Visual Studio Tools for Office.

Primary Interop Assembly Reference

This documentation describes all of the types in the Outlook primary interop assembly that you can use in Visual Studio Tools for Office projects:

  • It describes the types in the primary interop assembly for Outlook 2007. Therefore, if you are developing an Outlook 2003 add-in, you will not be able to use some of classes and members that appear in this documentation. For descriptions of types and members that are available for Outlook 2003, refer to the Microsoft Office Outlook 2003 VBA Language Reference.

  • It does not provide any code examples at this time.

VBA Reference

All of the objects and members in the VBA reference correspond to classes and members in the primary interop assembly that you use in Visual Studio Tools for Office projects. For example, the Inspector object in the Outlook VBA documentation corresponds to the Inspector class in the primary interop assembly.

The VBA reference has the following advantages:

  • It provides code examples for most members.

The VBA reference has the following disadvantages:

  • It provides syntax and code examples for VBA only. To use the code examples in a Visual Studio Tools for Office project, you must translate the VBA code to Visual Basic or Visual C#.

Additional Types in Primary Interop Assemblies

The primary interop assemblies contain many types that are not available to VBA. These additional types help translate objects in the COM-based object model of Outlook to managed code, are not intended to be used directly in your code.

For more information, see Architecture of the Outlook PIA.

See Also

Tasks

How to: Add Windows Forms to Outlook Solutions

How to: Add Custom Menus and Menu Items to Outlook

How to: Add Custom Toolbars and Toolbar Items to Outlook

How to: Add Custom Icons to Toolbar and Menu Items

How to: Maintain Position Information for Custom Toolbars between Outlook Sessions

How to: Read Data from a Custom Field of an Item

How to: Determine the Parent Folder of Unsaved Items

How to: Determine the Current Outlook Item

Concepts

Specific Security Considerations for Office Solutions

Office Solutions Development Overview

Working with Contact Items

Working with Mail Items

Working with Folders

Working with Calendar Items