ItemAdd event is not firing

Joined
Nov 10, 2011
Messages
5
Reaction score
0
Hi friends,

I am trying to create a outlook add in project. In that i need to flag the email that i send. if i add this code before the mail send

Code:
MailItem.FlagRequest = "Archive to CRM";

The recipient can also view the code. I dont want to view the flag by recipient. So i try to write that code in "items.ItemAdd" event. But that event is not firing at all.

Can anyone show me is there anything missing in the below code

Code:
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

namespace OutlookAddIn_Eg1
{
    public partial class ThisAddIn
    {
        private Outlook.Application _outlookApp;
        Outlook.Items items; 
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            _outlookApp = (Outlook.Application)this.Application;
            OutlookAddIn_Eg1.ContactClass.OutlookApp = _outlookApp;

            Outlook.Folder folder = Application.GetNamespace("MAPI").GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
            items = folder.Items;
            items.ItemAdd += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd); 
        }

        void Items_ItemAdd(object Item)
        {
            Outlook.MailItem MailItem = items as Outlook.MailItem;
            if (MailItem != null)
            {
                int x = 123;
            }


        } 
        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
        {
            return new Ribbon1();
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}


Thanks & Regards
bob
 
Back
Top