Click here to Skip to main content
Click here to Skip to main content

Outlook To OneNote AddIn

, 2 Mar 2007
Rate this:
Please Sign up or sign in to vote.
An article on creating a useful addin using Outlook and OneNote 2007

Introduction

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.

Background

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.
                   ApplicationEvents_11_NewMailEventHandler(olApp_NewMail);
}

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 this MSDN article. 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).

History

Article initially posted March 2007.

License

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
Engineer
United States United States
I am currently a software test engineer on the OneNote team at Microsoft.

Comments and Discussions

 
QuestionSetup.exe PinmemberMember 99676595-Apr-13 7:16 
AnswerRe: Setup.exe PinmemberJohn Guin5-Apr-13 7:55 
GeneralMessage Automatically Removed PinmemberMember 31108198-Mar-10 16:10 
Questionwhere is the setup.exe? Pinmemberpinacle20005-Mar-07 11:06 
AnswerRe: where is the setup.exe? PinmemberJohn Guin5-Mar-07 14:36 
GeneralRe: where is the setup.exe? Pinmemberpinacle20005-Mar-07 15:44 
GeneralRe: where is the setup.exe? PinmemberJohn Guin5-Mar-07 16:33 
GeneralRe: where is the setup.exe? Pinmemberpinacle20005-Mar-07 20:06 
GeneralRe: where is the setup.exe? Pinmemberpinacle20006-Mar-07 7:58 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 2 Mar 2007
Article Copyright 2007 by John Guin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid