none
Outlook Add In RRS feed

  • Question

  • Hi,

    I have to develop an Outlook Add-in for my Client. Basically what is required is to Categorize all Incoming Email.

    I had planned to do this by hooking Application.NewMailEx Event Handler. However this seems to work only for new email and it doesn't work when outlook is configured in Exchange Mode(cached).

    Also it doesn't work for new emails which are moved by rule to a different folder. And how to process emails which arrived when Outlook was Closed??

    Outlook Version 2007  & VS 2008
    Monday, July 4, 2011 6:42 AM

Answers

  • Hi richieferns,

     

    Thanks for posting in the MSDN Forum.

     

    As far as I know, NewMailEx will handle all of the mail item which you received. If the mail item has been received at other client, NewMailEx will not handle it.

     

    When you Outlook is launched, iterate all of the MAPIFolder’s mail item to check the specific UserProperty. If the mail item doesn’t have such UserProperty handle it and mark the UserProperty to it.

     

    After Outlook Launched. Let NewMailEx to handle the mail item which you received. In the NewMailEx process, we will set the specific UserProperty and save it at the end of process.

     

    This is my snippet which will explain my idea:

     

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
    
        {
    
          Application.NewMailEx += new Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);
    
        }
    
     
    
        void Application_NewMailEx(string EntryIDCollection)
    
        {
    
          Outlook.MailItem item = Application.Session.GetItemFromID(EntryIDCollection);
    
          Outlook.MAPIFolder folder = Application.Session.Stores["v-yangxu@microsoft.com"].GetRootFolder().Folders["Forum Alert"];
    
          if (item.Subject.Equals("Test+="))
    
          {
    
            item.UserProperties.Add("ReceiveFlag", Outlook.OlUserPropertyType.olYesNo);
    
            item.UserProperties["ReceiveFlag"].Value = true;
    
            item.Save();
    
          }
    
        }
    
     
    
    //This is in the Ribbon button. We aren't able to handle the item which receive on other Outlook client. 
    
        private void button1_Click(object sender, RibbonControlEventArgs e)
    
        {
    
          foreach (Outlook.Store store in Globals.ThisAddIn.Application.Session.Stores)
    
          {
    
            foreach (Outlook.MAPIFolder folder in store.GetRootFolder().Folders)
    
            {
    
              IteratorItem(folder);
    
            }
    
          }
    
        }
    
     
    
        private void IteratorItem(Outlook.MAPIFolder Folder)
    
        {
    
          foreach (var obj in Folder.Items)
    
          {
    
            if (obj is Outlook.MailItem)
    
            {
    
              Outlook.MailItem item = (Outlook.MailItem)obj;
    
              var flag = item.UserProperties["ReceiveFlag"];
    
              if (flag == null)
    
              {
    
                item.UserProperties.Add("ReceiveFlag", Outlook.OlUserPropertyType.olYesNo);
    
                item.UserProperties["ReceiveFlag"].Value = true;
    
                item.Categories = "红色类别";
    
                item.Save();
    
              }
    
            }
    
            foreach (Outlook.MAPIFolder f in Folder.Folders)
    
            {
    
              IteratorItem(f);
    
            }
    
          }
    
        }
    
    


     

     

    I hope it can help you.

     

    Have a good day,

     

    Tom

     

     


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 5, 2011 11:38 AM
    Moderator