Sharing the goodness…
Beth Massi is a Senior Program Manager on the Visual Studio team at Microsoft and a community champion for business application developers. Learn more about Beth.
More videos »
Last post I was talking about DataSets and aggregating data with LINQ and the example I gave was around finding rows of data where the Status = “Unread”. This got me thinking about how we could do this by asking Outlook for my unread email count – one of the programs I spend a lot of time in ;-). This actually is a pretty easy thing to do if you use the Primary Interop Assembly (PIA) for Outlook – Microsoft.Office.Interop.Outlook. Add a reference to your project and then import the namespace at the top of your program.
Then you can write the following code:
Dim OutlookApp As New Application()
Dim myMail As [NameSpace] = OutlookApp.GetNamespace("MAPI")
Dim count As Integer = myMail.GetDefaultFolder(OlDefaultFolders.olFolderInbox).UnReadItemCount
Note that if you have selected an Outlook Add-in project template in Visual Studio then you already have reference to the Application and you’re already logged in so the code is even simpler:
Dim myMail As [NameSpace] = Me.Application.GetNamespace("MAPI")
Dim unread As Integer = myMail.GetDefaultFolder(OlDefaultFolders.olFolderInbox).UnReadItemCount
PingBack from http://microsoft-sharepoint.simplynetdev.com/getting-a-count-of-unread-email-in-outlook/