How to Create a Custom Folder for a Custom Message Class with a Custom Form Region RRS feed

  • Question

  • I have searched everywhere for this, but everything I find is about creating the custom form region which I can already do.

    What I want is to programmatically create a "Widgets" folder in the navigation pane that works similar to the "Inbox" folder. I want that folder to only store items with a custom message class of "IPM.Widget" which will open with the form region I've already created. I can find samples on how to add the folder but not on how to configure the folder specifically for my message class. Can anybody point me in the right direction?

    Thursday, August 20, 2009 7:37 PM


  • Hi David,

    As far as I know, you could achieve this programmatically. Here are the steps.

    1. Use Newmail event when receiving a mail, then check the mail's class.
       Code block:

            Outlook.Application app;
            Outlook.Items items;
            Outlook.NameSpace ns;
            Outlook.MAPIFolder inbox;
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
                app = this.Application;
                ns = this.Application.Session;
                inbox = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
                items = inbox.Items;
                app.NewMail += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailEventHandler(app_NewMail);

    2. In the app_NewMail method, check the mail's class and then move this mail to the "Widgets" folder.
       Code block:

    void app_NewMail()
                Outlook.MailItem item;
                item= items.GetLast() as Outlook.MailItem;
                if (item.MessageClass == "IPM.Widget")
                    item.Move(DestFldr); //Move(Microsoft.Office.Interop.Outlook.MAPIFolder DestFldr)

    Since I don't know where is the "Widgets" folder you want to create, I write code snippet as below. You can make some changes to get the folder named DestFldr.
      Code block:

    foreach (Outlook.MAPIFolder rootFolder in this.Application.Session.Folders)
                    if (rootFolder.Name == "Local Main Mailbox")
                        foreach (Outlook.MAPIFolder folder in rootFolder.Folders)
                            if (folder.Name == "testss")
                                foreach (Outlook.MAPIFolder folder1 in folder.Folders)
                                    if (folder1.Name == "tests")
                                        foreach (Outlook.MAPIFolder folder2 in folder1.Folders)
                                            if (folder2.Name == "test")

    Best regards,

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Edited by Bessie Zhao Wednesday, August 26, 2009 11:30 AM
    • Marked as answer by Bessie Zhao Friday, August 28, 2009 5:40 AM
    Wednesday, August 26, 2009 11:28 AM