EWS Managed API: Fetch emails by search filter on DateTimeReceived

吃可爱长大的小学妹 提交于 2020-01-06 02:42:06

问题


While searching for items in the inbox that have been received after a particular time frame (as mentioned in the code below). It searches for the date but it is also returning the email with the specified timestamp. I want the emails only after the specified timestamp.

SearchFilter greaterthanfilter = new SearchFilter.IsGreaterThan(ItemSchema.DateTimeReceived,
                    Convert.ToDateTime(lastUploadedEmailtimeStamp));

mailItems = inbox.FindItems(greaterthanfilter, view);

Not sure if anyone has faced any similar issues? Basically I want to search for items that were received after a particular mm/dd/yyyy hh:mm:ss.


回答1:


Exchange stores the datetimes with a precision down to the Millisecond, EWS only give you a precision on datetimes to the second however the Searchfilters do have a precision of milliseconds with Date time. So if you datetime stamps your using only have a precision of seconds then you need to use something like this eg where you wanted all email that was received after 7:43 and 8 seconds

SearchFilter sfs = new SearchFilter.IsGreaterThan(ItemSchema.DateTimeReceived, DateTime.ParseExact("2014/12/29 07:43:08.999", "yyyy/MM/dd HH:mm:ss.fff", null));
FindItemsResults<Item> femaa = service.FindItems(WellKnownFolderName.Inbox,sfs, iItemView);

If you want to look at the actual precision on your messages you need to use a MAPI editor like OutlookSpy of MFCMapi. You can then look at the PT_Systime value which are FileTime "8 bytes; a 64-bit integer representing the number of 100-nanosecond intervals since January 1, 1601" see http://msdn.microsoft.com/en-us/library/ee157583(v=EXCHG.80).aspx

Cheers Glen



来源:https://stackoverflow.com/questions/27679099/ews-managed-api-fetch-emails-by-search-filter-on-datetimereceived

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!