Click here to Skip to main content
13,044,705 members (60,072 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 28 Jan 2008

Retrieve unread messages from Inbox

, 30 Jan 2008
Rate this:
Please Sign up or sign in to vote.
How to retrieve unread messages from Inbox by using Outlook Object Model in Visual Basic .NET


The article is about reading, mails for th outlook, I faced this requirement when my client told me to automate the reading the UNREAD mails from his inbox without any intervention. So I just created the basic application which could read the inbox mails.

This article describes how to use Microsoft Outlook 10.0 Object Library to retrieve unread messages from the Outlook Inbox in Visual Basic .NET(2005)

Basic Recquirement:

1. Out Look 2003 Should be configured on your machine.

2. Visual Studio 2005 installed on your machine

Using the code:

Start the new session(Console) application of and paste the Code below in your module1.vb

Before you run the code don't forget to add the references to the Microsoft Outlook 10.0 Object Library. to add the reference browse through Project->Add References select COM tab

then select "Microsoft Outlook 10.0 Object Library" and press OK.

Run the Application. The Console Window will show the all the UNREAD mails from outlook(2003) the INBOX.

Imports System.Reflection
'// Reference to Microsoft Outlook 11.0 Object Library
Imports Microsoft.Office.Interop.Outlook

Module Module1

    Sub Main()
        ' Create Outlook application.
        Dim oApp As Microsoft.Office.Interop.Outlook.Application = New Microsoft.Office.Interop.Outlook.Application

        ' Get Mapi NameSpace.
        Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace = oApp.GetNamespace("mapi")
        oNS.Logon("YourValidProfile", Missing.Value, False, True) ' TODO:

        ' Get Messages collection of Inbox.
        Dim oInbox As Microsoft.Office.Interop.Outlook.MAPIFolder = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)
        Dim oItems As Microsoft.Office.Interop.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 Microsoft.Office.Interop.Outlook.MailItem
        Dim i As Integer

        For i = 1 To oItems.Count
            oMsg = oItems.Item(i)

            Console.WriteLine("press any key to continue")

        ' Log off.

        ' Clean up.
        oApp = Nothing
        oNS = Nothing
        oItems = Nothing
        oMsg = Nothing
    End Sub

End Module


  • 29/01/08 - Basic Version
  • Hope this code will help you people. Happy coding.


    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


    About the Author

    Kiran K
    Web Developer
    India India
    No Biography provided

    You may also be interested in...

    Comments and Discussions

    Questionchange the account Pin
    Member 104943839-Jan-14 2:06
    memberMember 104943839-Jan-14 2:06 
    GeneralMy vote of 5 Pin
    ESSESSESS30-Nov-11 21:42
    memberESSESSESS30-Nov-11 21:42 
    GeneralWorks nice with Outlook 2007 Microsoft Outlook 12.0 Object Library Pin
    HaraldHeide29-Oct-09 23:51
    memberHaraldHeide29-Oct-09 23:51 
    GeneralHelp.. Pin
    hits200921-Mar-09 4:23
    memberhits200921-Mar-09 4:23 
    QuestionWhat if it is system administrator mail Pin
    AcidAndroid4-Mar-09 8:56
    memberAcidAndroid4-Mar-09 8:56 
    AnswerRe: What if it is system administrator mail Pin
    Randy_Miller19-Sep-10 11:04
    memberRandy_Miller19-Sep-10 11:04 
    GeneralLooking at other folders other then the Inbox Pin
    DJ Matthews25-Aug-08 8:44
    memberDJ Matthews25-Aug-08 8:44 
    QuestionHow to move, delete and flag messages as read? Pin
    ATRider14-Apr-08 19:04
    memberATRider14-Apr-08 19:04 
    AnswerRe: How to move, delete and flag messages as read? Pin
    Luke Singh2-Jul-08 9:13
    memberLuke Singh2-Jul-08 9:13 
    GeneralCool!! Works immediately and is simple! Pin
    ATRider14-Apr-08 10:04
    memberATRider14-Apr-08 10:04 
    QuestionNice but ?? Pin
    Kamal Singh D. Kharayat28-Jan-08 23:50
    memberKamal Singh D. Kharayat28-Jan-08 23:50 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web02 | 2.8.170713.1 | Last Updated 30 Jan 2008
    Article Copyright 2008 by Kiran K
    Everything else Copyright © CodeProject, 1999-2017
    Layout: fixed | fluid