none
Datetime filter on emails received within the previous 5 days RRS feed

  • Question

  • Hi, 

       I have a addin for Outlook 2013 that will auto accept a meeting invite if sent from a certain email address. If the user is away and does not open Outlook for a period of 5 day I want to create the functionality where on startup the addin will take all mail from the previous 5 days and determine if there are any MeetingItems and process accordingly. I am having difficulty with this filter.

     void ThisApplication_MAPILogonComplete()
            {
                ItemInRange();
            }
            private void ItemInRange()
            {
                DateTime end = DateTime.Now;
                DateTime start = end.AddDays(-5);
                GetAppointmentsInRange(inbox, start, end);
            }
    
            private void GetAppointmentsInRange(Outlook.MAPIFolder folder, DateTime start, DateTime end)
            {
                string endTime = end.ToString("MM/dd/yyyy HH:mm");
                string startTime = start.ToString("MM/dd/yyyy HH:mm");
                string restrictCriteria = "[Start] >= '" + startTime + "' AND [End] <= '" + endTime + "'";
             
                Outlook.Items folderItems = null;
                Outlook.Items resultItems = null;
                Outlook._AppointmentItem appItem = null;
                int counter = default(int);
                object item = null;
                try
                {
                    folderItems = folder.Items;
                    folderItems.IncludeRecurrences = true;
                    //folderItems.Sort("[Start]");
                    resultItems = folderItems.Restrict(restrictCriteria);
                    item = resultItems.GetFirst();
    
    ...
    folderItems is getting the 5000+ emails in my inbox, but when I apply the filter resultItems.Count = 0. The filter as of the time of writing is:  restrictCriteria "[Start] >= '04/08/2016 08:29' AND [End] <= '04/13/2016 08:29'"

    Wednesday, April 13, 2016 12:47 PM

Answers

All replies