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:
- Send yourself an email with the filter text "onon" in the subject (not case sensitive)
- The body text of the mail will be made into a new page in the unfiled notes section
- "Power users" can change the filter text via a reg key- hkcu/sw/ms/office/outlook/OutlookToOneNoteAddIn.connect/filter string
- After the page is created the mail item gets moved to deleted items in Outlook
- 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:
- Attachments, images, OLE objects support.
- Limited to IPM.Note items in Outlook, so custom forms, meetings, etc.. will not be processed.
- 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)
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 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).
Article initially posted March 2007.