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.

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access