Click here to Skip to main content
15,881,938 members
Articles / Productivity Apps and Services / Microsoft Office

Creating an Outlook 2010 Add-In

Rate me:
Please Sign up or sign in to vote.
4.94/5 (11 votes)
10 May 2011CPOL2 min read 164.3K   6.9K   41   18
Create an add-in that automatically marks items as read when they are deleted in Outlook 2010.

Introduction

In this article, I will cover creating a simple Outlook add-in as well as the setup project to get it installed.

Background

It has always driven me crazy to have that little number next to my Deleted Items telling me that I have unread mail. I finally got fed up and created this little Outlook add-in to make sure that anything I move to Deleted Items also gets marked as read.

That is why I created the add-in. I'm writing this article mostly to share the plug-in, but also to show what I learned about writing add-ins for Outlook, or more aptly installers for Outlook add-ins.

Using the Code

The code for marking items as deleted is actually very simple. First we need to create a new project and choose "Outlook 2010 Add-In" as the project type.

NewProject.PNG

Then expand the "Outlook" group, and open ThisAddIn.cs. In the ThisAddIn_Startup method, we are going to add an event handler:

C#
Outlook.MAPIFolder deletedFolder = 
  this.Application.Session.GetDefaultFolder(
  Outlook.OlDefaultFolders.olFolderDeletedItems);
deletedFolder.Items.ItemAdd += 
  new Outlook.ItemsEvents_ItemAddEventHandler(DeletedItems_ItemAdd);

Then in the event handler, we just mark the item as read. I check for a number of other item types as well in the provided source, but they all look essentially like this:

C#
if(Item is Outlook.MailItem)
{
    (Item as Outlook.MailItem).UnRead = false;
}

That's it. Close Outlook and click the Run button, and the debugger will open Outlook with the add-in running. You can test it out and verify that it is marking things as read when you send them to Deleted Items.

Installing the Add-In

First we need to create a new setup project.

NewSetup.PNG

Once you've created the setup project, switch to Release and rebuild the solution. If you click on the setup project in Solution Explorer, and you'll see a series of tools of buttons at the top of Solution Explorer. We'll be using the File System Editor and the Registry Editor.

File System Editor

In the file system editor, we are going to right click on the Application folder to add a few things:

  • Project Output->Primary Output
  • File->MarkDeletedItemsRead.dll.manifest (from the bin\release folder)
  • File->MarkDeletedItemsRead.vsto (from the bin\release folder)

Registry Editor

In the Registry editor, we need to create the key HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\Addins\Mark Deleted Items Read.

The final key name isn't important, but you don't want it to match the add-in project name because VS will be overwriting that key when debugging.

We then need to create string values for Description, FriendlyName, and Manifest. You can put whatever you like for the first two values, but the Manifest's value should be "[TARGETDIR]MarkDeletedItemsRead.vsto|vstolocal".

Rebuild the setup project and you should be able to install from Setup.exe in the bin\release folder.

History

  • 05/10/11 - Initial release.

License

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


Written By
Software Developer
United States United States
I’m a Software Engineer at Microsoft working on the Azure Portal. Before that I spent about 20 years developed various business applications at a number of different companies. I have a passion for writing clean, scalable code and sharing what I’ve learned with others.

I also help run the Casco Bay .Net User Group

Comments and Discussions

 
QuestionPossible Garbage collection issue Pin
percy198426-Jun-15 2:32
percy198426-Jun-15 2:32 
BugRe: Possible Garbage collection issue Pin
Member 1292521227-Dec-16 23:55
Member 1292521227-Dec-16 23:55 
QuestionNot able to see .vsto and manifest file after building the solution Pin
sma123#19-Mar-15 20:52
sma123#19-Mar-15 20:52 
QuestionUnable to find VSTO file Pin
Member 104981349-Feb-14 16:40
Member 104981349-Feb-14 16:40 
AnswerRe: Unable to find VSTO file Pin
Jeremy Hutchinson10-Feb-14 1:36
professionalJeremy Hutchinson10-Feb-14 1:36 
GeneralRe: Unable to find VSTO file Pin
Member 1049813410-Feb-14 4:21
Member 1049813410-Feb-14 4:21 
QuestionWhat am I missing? Pin
GuyM24-Dec-12 2:56
GuyM24-Dec-12 2:56 
GeneralMy vote of 3 Pin
Sameerkumar Namdeo12-Dec-12 20:44
Sameerkumar Namdeo12-Dec-12 20:44 
QuestionAddIn not opening this way for me Pin
Member 944443020-Sep-12 7:13
Member 944443020-Sep-12 7:13 
QuestionC# source Code Pin
sonia samimi16-Sep-12 22:04
sonia samimi16-Sep-12 22:04 
Generalerror when using this code Pin
DeeDub19-Jul-12 20:46
DeeDub19-Jul-12 20:46 
GeneralRe: error when using this code Pin
Jeremy Hutchinson20-Jul-12 1:03
professionalJeremy Hutchinson20-Jul-12 1:03 
SuggestionLoadBehavior key is also necessary to load the addin correctly. Pin
surlary15-Jul-12 22:52
surlary15-Jul-12 22:52 
QuestionIn addition to the article Pin
predei31-May-12 7:35
predei31-May-12 7:35 
General"MarkDeletedRead" downloaded compile attempt using VisualStudio 2010 error MSB3323 "Unable to find manifest signing certificate in certificate store" Pin
RedDk20-May-11 7:19
RedDk20-May-11 7:19 
GeneralRe: "MarkDeletedRead" downloaded compile attempt using VisualStudio 2010 error MSB3323 "Unable to find manifest signing certificate in certificate store" Pin
Jeremy Hutchinson20-May-11 7:34
professionalJeremy Hutchinson20-May-11 7:34 
GeneralRe: "MarkDeletedRead" downloaded compile attempt using VisualStudio 2010 error MSB3323 "Unable to find manifest signing certificate in certificate store" Pin
RedDk20-May-11 8:09
RedDk20-May-11 8:09 
GeneralThank you! Pin
Pranav Ainavolu10-May-11 8:03
Pranav Ainavolu10-May-11 8:03 

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.