How to retrieve unread messages from Inbox by using Outlook Object Model in Visual Basic .NET

If you want to know how to retrieve unread messages from Inbox by using Outlook Object Model in Visual Basic .NET then the Process to retrieve unread message from outlook inbox is given in this article. You will get the solution how to retrieve unread message from outlook inbox by using outlook object model in visual basic. This is very necessary to retrieve unread message of outlook inbox. The process that is given to retrieve is explained briefly in the below paragraph. If you want to apply it into the computer then you have to read the entire content and apply the process step by step in your computer.

Download Outlook PST Repair Tool

Process to retrieve unread message from outlook inbox

First of all open Microsoft visual studio and then click on the file menu and then click on new project and then click on visual basic projects that is in the project types and after that you have to click on console application. Now you have to add a reference to the Microsoft outlook 10.0 object libraries and then click on add reference in the project menu. Now click on COM tab and then you have to click on Microsoft Outlook 10.0 Object Library and then click on select and then click on ok. copy the following code and paste into the Microsoft visual basic code window.

Imports System.Reflection

Module Module1

Sub Main()

‘ Create Outlook application.

Dim oApp As Outlook.Application = New Outlook.Application()

‘ Get Mapi NameSpace.

Dim oNS As Outlook.NameSpace = oApp.GetNamespace(“mapi”)

oNS.Logon(“YourValidProfile”, Missing.Value, False, True) ‘ TODO:

‘ Get Messages collection of Inbox.

Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)

Dim oItems As Outlook.Items = oInbox.Items

Console.WriteLine(“Total : ” & oItems.Count)

‘ Get unread e-mail messages.

oItems = oItems.Restrict(“[Unread] = true”)

Console.WriteLine(“Total Unread : ” & oItems.Count)

‘ Loop each unread message.

Dim oMsg As Outlook.MailItem

Dim i As Integer

For i = 1 To oItems.Count

oMsg = oItems.Item(i)

Console.WriteLine(i)

Console.WriteLine(oMsg.SenderName)

Console.WriteLine(oMsg.Subject)

Console.WriteLine(oMsg.ReceivedTime)

Console.WriteLine(oMsg.Body)

Console.WriteLine(“—————————“)

Next

‘ Log off.

oNS.Logoff()

‘ Clean up.

oApp = Nothing

oNS = Nothing

oItems = Nothing

oMsg = Nothing

End Sub

End Module

Download Outlook PST Repair Tool

After that press f5 to run the application and by this process you will able to retrieve unread message from outlook inbox.

Leave a Reply

Your email address will not be published. Required fields are marked *