Click here to Skip to main content
15,397,729 members
Articles / Programming Languages / C#
Posted 1 Feb 2007


16 bookmarked

Outlook To OneNote AddIn

Rate me:
Please Sign up or sign in to vote.
2.40/5 (2 votes)
1 Feb 20074 min read
An article on creating a useful addin using Outlook and OneNote 2007


This Addin is designed to solve a problem some users of OneNote face. Once people start using OneNote, many of them tend to move all their data into it. They then experience the problem of being away from OneNote and having information they want to add to it. Their only access may be to email, such as with a mobile phone or airport kiosk. They could rely on new functionality in Outlook 2007 which gives a ribbon button to send the contents of email to OneNote. There is a step or two here which can be eliminated with this addin.

This addin adds the capability of sending yourself email with a certain keyword in the subject and having Outlook automatically create a new page in OneNote's Unfiled Notes section when that mail item arrives. Outlook then deletes the email. It also allows power users to set the filter used for incoming mail items to trigger the code. It provides no UI for the user: "it just works."

I also included the setup project since it is needed to create the registry key when executed. If you just want to install and use the addin, the Setup zip file is all you need. Exit all office apps and run setup.exe.


This addin uses both the Outlook 2007 Object Model to work with the Outlook item and the OneNote 2007 XML API to add the page to OneNote.

The OneNote 2007 XML API is documented here. The Outlook 2007 OM reference is here.

The Design Goals

Here are my goals for this addin, driven almost entirely from the scenario I describe above:

  1. Send yourself an email with the filter text "onon" in the subject (not case sensitive)
  2. The body text of the mail will be made into a new page in the unfiled notes section
  3. "Power users" can change the filter text via a reg key- hkcu/sw/ms/office/outlook/OutlookToOneNoteAddIn.connect/filter string
  4. After the page is created the mail item gets moved to deleted items in Outlook
  5. Plain text, rich text or html mail formats will be supported (since the user can't control the email client at the kiosk in this scenario)

Functionality I will not implement:

  1. Attachments, images, OLE objects support.
  2. Limited to IPM.Note items in Outlook, so custom forms, meetings, etc.. will not be processed.
  3. Message flags and importance are not transferred.

Using the code

Before I even got to writing the code, I had to get my project to reference the Outlook 12 object model and the OneNote 12 API. I added a reference to both the COM libraries in my Visual Studio project. Knowing I would need some XML manipulation, I added a reference to System.XML.

I wanted the filter for the subject line to be settable by the user. I did not want any UI to show with this addin, so I decided to create a registry key to store the filter. The casual user can use the default text string of "onon" - which should be easy to remember and type on a cell phone - and the power user can alter the registry key if needed.

The only event I need from Outlook is the new mail notification event.

public void OnStartupComplete(ref System.Array custom)
    //register for the new mail event in Outlook
      olApp.NewMail += 
          new Microsoft.Office.Interop.Outlook.

Then the application just waits for the new mail event to fire and checks to see if the inbound item (of IPM.Note only) matches the filter criteria. If so, the code looks through the existing OneNote heirarchy to find the UnfiledNotes section where it adds the body of the message as a page. Then it deletes the mail item.

Points of Interest

There wasn't a lot to this addin. One interesting note is using the HTMLBody property of the Outlook mail item. Outlook supports rich and plain text mail formats as well as HTML. Initially, I used only the Body property of the email item: string emailBody = mail.Body; but noticed that the formatting was lost if the received mail item was either rich or plain text. Since OneNote uses html formatting within it's XML, I changed my code to use the HTMLBody property and retained the formatting after reading the article at I'm taking advantage of the default behavior of OneNote to set the title of the page. Since I do not explicitly set the title in my code, OneNote uses the first few words of the text of the body to use as a the title of the page. An idea to extend this would be to use the subject of the email, minus the filter, as the title.

Some thanks are in order. The code for getting to the UnfiledNotes section was taken from the OneNote Sidebar gadget available on the Microsoft website. Henrieta Slugenova pointed out some limitations of this implementation during her testing. I incorporated them into the "Ideas for Improvement" below. And to David Rasmussen for the idea. He has a blog here.

Ideas for Improvement

Add UI to allow user to change the filter text. Allow user to set where in OneNote these emails are sent. Attachment and image support. Or, recreate this solution as a custom action for the Outlook Rules Wizard (where it seems to make more sense in some ways).


Article initially written in January 2007.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

John Guin
United States United States
I am currently a software test engineer on the OneNote team at Microsoft.

Comments and Discussions

QuestionSave to different notebook Pin
John Nutter20-Jul-11 10:26
MemberJohn Nutter20-Jul-11 10:26 
AnswerRe: Save to different notebook Pin
John Guin28-Jul-11 13:52
MemberJohn Guin28-Jul-11 13:52 
QuestionWhere can i get the onenote gadget at? Pin
werD18-Mar-08 23:11
MemberwerD18-Mar-08 23:11 
AnswerRe: Where can i get the onenote gadget at? Pin
John Guin19-Mar-08 18:39
MemberJohn Guin19-Mar-08 18:39 
GeneralUpdated location for setup Pin
John Guin9-Feb-07 6:08
MemberJohn Guin9-Feb-07 6:08 
GeneralThe reg key needed Pin
John Guin2-Feb-07 4:19
MemberJohn Guin2-Feb-07 4:19 

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.