none
Items.ItemAdd function is not triggering RRS feed

  • Question

  • Hi

    In my outlook i have configured 2 email, myemail1@gmail.com and myemail2@gmail.com and "myemail1@gmail.com" is default outlook email id.

    I have an outlook addin and in it there is function called "Mail_Send" This function will trigger when mail is send. This function is working fine for all cases. But in this function i initialize a new function called Items.ItemAdd. My aim is this function will trigger after the mail is send. Its working fine, If i send a mail from my default outlook mail id. Its not working when i send mail from "myemail2@gmail.com". If i set the default mail id to "myemail2@gmail.com", it will work only this mailid. I will paste here my code.

    private void Mail_Send(ref bool Cancel)
            {
    SentMailSubject = tempMail.Subject;
                        Outlook.MAPIFolder folder = (MAPIFolder)this.OutlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
                        folder.Items.ItemAdd+=new ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
    }
    
    private void Items_ItemAdd(object Item)
            {
                string Filter = "[subject] = '" + SentMailSubject + "' And [SentOn] >'" + MailSendOn.ToString("g") + "'";
    
                Outlook.MAPIFolder folder = (MAPIFolder)this.OutlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
                Outlook.Items AllSentItems = folder.Items;
                AllSentItems.Sort("[SentOn]", true);
                Outlook.MailItem Items = AllSentItems.Find(Filter) as Outlook.MailItem;
                MessageBox.Show("2");
                while (Items != null)
                {
                    Items.Categories = HelperClass.AddSugarCategory(Items.Categories);
                    Items = AllSentItems.FindNext() as Outlook.MailItem;
                }
            }

    Thanks & Regards

    Bobbin

    Wednesday, November 14, 2012 12:11 PM

Answers

  • 2 problems:

    1. you have to store somewhere object on which you attach to events - here Items class, storing just Folder class will not work

    2. you attach to sentitems folder on your main account - if you send mails from secondary accounts, mails will land in sentitems folders for those accounts, not for main one. so iterate through all stores and get their sentitems folders and attach to their events.

    • Marked as answer by Bobbin Paulose Wednesday, November 14, 2012 4:54 PM
    Wednesday, November 14, 2012 12:35 PM