Monday 30 November 2015

Access your Email within Outlook (Final Part) C#

Introduction

This is an introduction to Microsoft Outlook and its accessible properties and methods you can access through C#. We will not be working with the entire set of properties and methods, just the properties that can be attributed to an email. We will be showing you how to access your Outlook email through C# and how to display that information on a screen.
In this final article of this series we finalize the remaining coding and access the remaining properties needed to populate our screen. We will also display a screen shot of the final solution with the data populated from the first email returned in the Outlook collection object.

Implementation

In this article we will be working with Microsoft Outlook and its accessible properties and methods. We will be inserting a reference to the Outlook Namespace and accessing the Inbox to see if we can locate an email. If we find an email we will then go ahead and display the first email we find, and even display the name of the first attachment in that email.

Sender Name

In order to return the Sender’s Name of an email we will need to cast the item within the MAPI Inbox folder to a MailItem. Once it has been correctly casted you can then access the Sender’s Name property.

Email Creation date

In order to return the Creation Date of an email we will need to cast the item within the MAPI Inbox folder to a MailItem. Once it has been correctly casted you can then access the Creation Date property.
You have now added all of the necessary property calls and have returned all of the information required to populate the application screen we have created. For a visual representation of the final solution please refer to Fig. 5.
Compile and execute the above code. When the application starts you will be presented with a screen that will allow you to select a button to “Access Email” from your local installation of Outlook. The results of that access test will be displayed in the fields on the screen.