Freigeben über


Generate Documents Out Of Mail Items Directly From Outlook 2007

Information is all over – emails, blogs, notes, posts. While I consolidate incoming information in my Inbox (My Pipeline Is My Inbox) it may end spread all over in my OL folders. Even if I had one folder for all – it is collection of mail items, but not single document. What I would love to have is an ability to generate documents from these mail items and then share it.

Here are 5 steps I’ve taken to create this ability that lets me now generate documents directly from Outlook 2007.

  1. Have Visual Studio 2005 installed
  2. Download and install VSTO SE
  3. Download code sample from https://channel9.msdn.com/ShowPost.aspx?PostID=259129#259129. The sample shows how to add menu item to Outlook 2007
  4. Here is what I have in my Outlook 2007 after installing the addin I created using the sample:cid:image001.png@01C79B08.50FF9800
  5. In event handler run through some folder, concatenate its contents, and save to the file

//THE FOLLOWING CODE IS REALLY DIRTY…. I HAVE 12 PST’s, so I am picking the last one and second folder in in it. Use you imagination to make it more flexible.

            Outlook.MAPIFolder inBoxfolder = Application.Session.Stores[12].GetRootFolder().Folders[2];

            StringBuilder sb = new StringBuilder();

            for (int i = 1; i <= inBoxfolder.Items.Count; i++)

            {

           if (inBoxfolder.Items[i] is Outlook.PostItem)

                {

                    Outlook.PostItem pi = (Outlook.PostItem)inBoxfolder.Items[i];

                    sb.Append("<h1>");

                    sb.Append(pi.Subject);

                    sb.Append("</h1>");

                    sb.Append(pi.HTMLBody);

                    sb.Append("<hr>");

                }

            }

           using (StreamWriter sw = new StreamWriter(@"C:\GeneratedFile.htm"))

            {

                sw.Write(sb.ToString());

            }

Here is the scenario where I can apply it.

I am dev team lead and I want to share some rough thoughts on AJAX with my team. I go ahead and subscribe to couple of feeds for the subject (more on that here - How to Use Outlook 2007 RSS To Effectively Aggregate And Distill Information). Now I have some blog posts about it in my Outlook 2007, I drag it into resulting folder – the one that the above code handles. Then I add some private collection on the subject by pressing Cntrl+Shift+S (more shortcuts here My Favorite Shortcuts) and paste there AJAX links. Here is how AJAX collection might look:

cid:image002.png@01C79B09.D71C5E40

 Then I run the code I developed using VSTO and it generates nice HTML doc. One obstacle though (hypothetically) – I cannot send it to the team since the only document format I can send is PDF, so I copy-paste ( which is my favorite design pattern – more on patterns here AOP, Pipelines, Interceptors, and HttpModlues) the contents into Word 2007. While I am in Word 2007 I decide to add nice table of contents and then convert it into PDF.

I am all set to share the document with the team. Want it too? Here it is.

Enjoy

Thanks Oren for helping me with VSTO.

Comments

  • Anonymous
    January 03, 2008
    patterns&amp;practices recently released new version of Guidance Explorer [GE]. One of the most important
  • Anonymous
    January 15, 2008
    Do you conduct security code reviews? - [Yes/No] Do you want to streamline the process of the review?