Process incoming mail using an outlook Addin

A customer raised an incident to Microsoft wanting to know how they can create an addin in Outlook to watch all incoming mail....and then do something with it.

So I figured if it's a call to Microsoft that needed this and I see a few people asking how to do this on the Microsoft forums, well it's worth a quick blog post about it.


Here are the steps to get you going:

- Start up your Visual Studio 2010 environment

- Choose File | New | Project... this dialog will appear, i've chosen my target environment Office 2010

- Create a name for your addin (WatchIncomingMailAddin)

 - Let Visual Studio create the default template for the outlook addin

- After it has done this, you will see this code


- Select all that code and replace it with the text below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

namespace WatchIncomingMailAddin
    public partial class ThisAddIn
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
            Outlook.MAPIFolder inbox = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);    
           inbox.Items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(InboxFolderItemAdded);        }
        private void InboxFolderItemAdded(object Item)
            if (Item is Outlook.MailItem)
                // New mail item in inbox folder
                MessageBox.Show("you got mail");

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);

The code above :

 - sets up namespace to allow us to use the message box (

 - set up a session to determine the correct folder that we want to process (inbox)

 - set up an event handler to fire when a new item arrives in the inbox (InboxFolderItemAdded)

 - In our event handler we set up a message box in the event to alert us


Make sure the outlook process is shut down before running this code as visual studio will process it will automatically at runtime by registering it and tehn fire up outlook

- Run the Addin

- wait for a new mail (or send yourself one)

- You should now see the message fire "You got mail"


As it's an outlook.mailitem, you can do lots of things to this, here are a list of members that the mailitem exposes


Hope thats been helpful, here are some links for reference worth noting to help you with your Outlook office development

Outlook Solutions with Visual Studio

Walkthrough: Creating Your First Application-Level Add-in for Outlook

What's New for Developers in Outlook 2010

Office Development with Visual Studio (VSTO)


Comments (2)

  1. Vibhav Pant says:

    Joshi ji, what if we have some outlook rules, those emails never comes to inbox. They go directly to some other folders as per the rule. This event handler is not able to catch those emails.
    Is there a way to catch all those emails before Outlook rules process them?, Or
    Do we need to add separate event handlers for all the folders? If Yes, any suggestions how to do it, so that it will work for different users, who may have different folders.

  2. sam says:

    Error 1 The “FindRibbons” task could not be loaded from the assembly Microsoft.VisualStudio.Tools.Office.BuildTasks, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. WatchIncomingMailAddin

Skip to main content