Using Outlook and MAPI

Messaging Application Programming Interface (MAPI) is a set of COM libraries in Windows that allows one to develop applications and plug-ins for Microsoft Outlook and other messaging applications that support it (Exchange, Windows Messaging, etc.). We will be using MAPI to get the data we require from Outlook for our application.

Earlier, we created a contract named IWHSMailService. This contract will be implemented by the WHSMailService class, also created earlier. To do this, back in the WHSMailHost project, set a reference to the solution's WHSMailCommon assembly. Then, set a reference to the Microsoft Outlook 12.0 Object Library, which you will find under the COM tab (assuming Outlook is installed as per the instructions earlier), as shown in Figure 7-7.

Microsoft Outlook 12.0 Object Library reference

Figure 7-7. Microsoft Outlook 12.0 Object Library reference

Then, bring the Contracts and Entities namespaces into the WHSMailService class and set up the interface implementation with the code in either Example 7-14 or Example 7-15.

Example 7-14.  C# code for the base WHSMailService class

using WHSMailCommon.Contracts;
using WHSMailCommon.Entities;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace WHSMailHost
{
    public class WHSMailService : IWHSMailService
    {
    }
}

Example 7-15.  Visual Basic code for the ...

Get Coding4Fun now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.