none
How to use advanced search to find mail that is about to expire set by Outlook 2010 retention policy? RRS feed

  • Question

  • Hello,

    I am developing an outlook add-in to help corporate Outlook users find mail items that are about to get deleted by the IT department's implemented retention policy. I've been unsuccessfully combing through article after article to try to find out how a user can figure out which mail items are set to expire via corporate implemented retention.

    I've used a multitude of approaches, but none seem to work.  Currently here is my search string I'm using with Global.AdvancedFind method:

    string scope = "'" + inboxFolder.FolderPath + "'";
    string.expiresFilter = String.Format(@"urn:schemas:mailheader:expires>'{0}' ANDurn:schemas:mailheader:expires<'{0}', DateTime.Now, DateTime.Now.AddDays(31));

    Outlook.Search search = Globals.ThisAddIn.Application.AdvancedSearch(scope, expiresFilter, true, "Expiring Emails");

    As you can see above, I'm using the mailheader schema to try to determine whether a mail item is set to expire.  However, my results are incorrect because it doesn't return anything when in fact I know I have several items that are about to expire.  This leads me to believe that the retention tag information is not contained with the mailheader schema, so then where?  How can I find mail items that are about to expire that is set from the server?
    Tuesday, April 30, 2013 7:46 PM

All replies

  • Any Internet mail headers in Outlook are just blobs of text in one string property (PR_TRANSPORT_MESSAGE_HEADERS). To retrieve individual headers or x-headers you would need to use string parsing functions, a search can't do that.
     
    The easiest thing probably would be to use a MAPI viewer such as MFCMAPI (from codeplex) or OutlookSpy (www.dimastr.com/outspy) and see what properties if any are added to items to mark them for expiration.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "TheMagman" <=?utf-8?B?VGhlTWFnbWFu?=> wrote in message news:5c618a1e-2a54-4cb1-93c5-b76dc30fd2de...

    Hello,

    I am developing an outlook add-in to help corporate Outlook users find mail items that are about to get deleted by the IT department's implemented retention policy. I've been unsuccessfully combing through article after article to try to find out how a user can figure out which mail items are set to expire via corporate implemented retention.

    I've used a multitude of approaches, but none seem to work.  Currently here is my search string I'm using with Global.AdvancedFind method:

    string scope = "'" + inboxFolder.FolderPath + "'";
    string.expiresFilter = String.Format(@"urn:schemas:mailheader:expires>'{0}' ANDurn:schemas:mailheader:expires<'{0}', DateTime.Now, DateTime.Now.AddDays(31));

    Outlook.Search search = Globals.ThisAddIn.Application.AdvancedSearch(scope, expiresFilter, true, "Expiring Emails");

    As you can see above, I'm using the mailheader schema to try to determine whether a mail item is set to expire.  However, my results are incorrect because it doesn't return anything when in fact I know I have several items that are about to expire.  This leads me to believe that the retention tag information is not contained with the mailheader schema, so then where?  How can I find mail items that are about to expire that is set from the server?

    Ken Slovak MVP - Outlook
    Wednesday, May 1, 2013 1:51 PM
    Moderator
  • Thanks Ken Slovak,

    While there is a mail expiration field contained in the headers (httpmail schema) (something that OutlookSpy can pick up), the email retention policy is set on the server and is not actually contained in the header of the mail item.  Outlook 2010 and 2013, does however, download these headers at a syncing time, but may not necessarily get updated in the store on the clients' machine.  Therefore, the search would have had to occur on on the server side by a client request.

    The information is very sparse on MSDN and in fact, I found it on a technet blog and isn't even listed as an item in the outlook reference.

    I found my answer, but unfortunately I'm not in front of the code to copy and paste.  It was rather trivial once you actually found the property... which wasn't listed in MSDN.  Thanks Microsoft!


    Tuesday, May 7, 2013 4:30 PM
  • Hi,

    Can you post the blog link? This will be helpful to other community members.

    Many thx.


    with regards, Yuri

    Friday, May 10, 2013 7:04 AM