none
Email searching in Outlook RRS feed

  • Question

  • Hi

    I am implementing a tool that uses the Outlook Object Model to search for emails that were received and sent on a specific date. I am using VB.NET in .NET 4.0.

    To achieve this in my search routine, I am retrieving references to the Inbox and Sent Items folders. For each of these two folders and their sub folders, I am using the Folder.GetTable() method. I know that Outlook.MailItem objects have ReceivedTime and SentOn properties that I can use to retrieve receive time and sent time respectively. So I am setting up my filter text (parameter to GetTable() method) as

    "[ReceivedDate] = '<DateValue in m/d/yyyy format>' OR [SentOn] = '<DateValue in m/d/yyyy format>'"

    This is not working at all. I have tried removing the OR and using only one condition instead of two - still no luck.

    I welcome any suggestions as to what could be wrong or perhaps a better way to achieve what I want (instead of using the GetTable() method)

    Thanks and regards

    Terence

    Tuesday, March 6, 2012 9:55 AM

Answers

  • Did you actually look at the article I recommended? For one thing you don't use seconds in a date filter, as is mentioned in that article:

    When using a date to search with the Find or Restrict method, the date in the search string must be formatted as an unambiguous string, not a date literal, and must contain only years, months, days, hours, and minutes -- no seconds. 

    "[ReceivedTime]" is a valid property to use. Look at the Object Browser for any Outlook item to see what properties are available for that type of item.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
     
     
    "TJoubert" <=?utf-8?B?VEpvdWJlcnQ=?=> wrote in message news:41d941ec-5815-4769-bda5-9187d133528b...

    Thanks for feedback. However the issue is not solved with what you have proposed. I am presently running tests on Inbox folder, using a filter like below (I am supplying today's date for comparison):

    searchFilter = "[ReceivedTime] >= '2012/3/6 00:00:00' AND [ReceivedTime] <= '2012/3/6 23:59:59'"

    The above filter still fails.

    Questions for which I cannot find any answer in MSDN's massive library:

    1) Is there a "ReceivedTime" attribute that can be used in a filter statement? If not, what are the filter attributes for Received Date/Time of the email and Sent Date/Time of the email?

    2) Does the date format depend on the local date/time settings or is there a universal format that Outlook Object Model supports? If it depends on local settings, will DateTime.ToShortDateString() method work?

    Thanks for any feedback that you may provide. 

    Regards

    Terence


    Ken Slovak MVP - Outlook
    • Marked as answer by TJoubert Tuesday, March 6, 2012 5:20 PM
    Tuesday, March 6, 2012 4:31 PM
    Moderator
  • Ken, my last post was replying to DamianD's reply to my original post. I had written it before seeing your post.

    Thanks for the article.  It has given me a lot of tips. I managed to get it to work in VB.NET using the following statement:

    "[ReceivedTime] >= '" & Format(DateTime.Now, "ddddd") & " 12:00 AM' AND [ReceivedTime] <= '" & Format(DateTime.Now, "ddddd") & " 11:59 PM'"

    Regards

    Terence

    • Marked as answer by TJoubert Tuesday, March 6, 2012 5:21 PM
    Tuesday, March 6, 2012 5:08 PM

All replies

  • First you should be using greater then or equal, not just equal so change your =  to >=.

    Second - i'm not sure about your datetime formats, i use yyyy/mm/dd but it is up to you to find out if your format works for you.

    Tuesday, March 6, 2012 10:12 AM

  • --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
     
     
    "TJoubert" <=?utf-8?B?VEpvdWJlcnQ=?=> wrote in message news:7fd030fa-596d-483c-8810-966b41c9d091...

    Hi

    I am implementing a tool that uses the Outlook Object Model to search for emails that were received and sent on a specific date. I am using VB.NET in .NET 4.0.

    To achieve this in my search routine, I am retrieving references to the Inbox and Sent Items folders. For each of these two folders and their sub folders, I am using the Folder.GetTable() method. I know that Outlook.MailItem objects have ReceivedTime and SentOn properties that I can use to retrieve receive time and sent time respectively. So I am setting up my filter text (parameter to GetTable() method) as

    "[ReceivedDate] = '<DateValue in m/d/yyyy format>' OR [SentOn] = '<DateValue in m/d/yyyy format>'"

    This is not working at all. I have tried removing the OR and using only one condition instead of two - still no luck.

    I welcome any suggestions as to what could be wrong or perhaps a better way to achieve what I want (instead of using the GetTable() method)

    Thanks and regards

    Terence


    Ken Slovak MVP - Outlook
    Tuesday, March 6, 2012 4:16 PM
    Moderator
  • Thanks for feedback. However the issue is not solved with what you have proposed. I am presently running tests on Inbox folder, using a filter like below (I am supplying today's date for comparison):

    searchFilter = "[ReceivedTime] >= '2012/3/6 00:00:00' AND [ReceivedTime] <= '2012/3/6 23:59:59'"

    The above filter still fails.

    Questions for which I cannot find any answer in MSDN's massive library:

    1) Is there a "ReceivedTime" attribute that can be used in a filter statement? If not, what are the filter attributes for Received Date/Time of the email and Sent Date/Time of the email?

    2) Does the date format depend on the local date/time settings or is there a universal format that Outlook Object Model supports? If it depends on local settings, will DateTime.ToShortDateString() method work?

    Thanks for any feedback that you may provide. 

    Regards

    Terence

    Tuesday, March 6, 2012 4:25 PM
  • Did you actually look at the article I recommended? For one thing you don't use seconds in a date filter, as is mentioned in that article:

    When using a date to search with the Find or Restrict method, the date in the search string must be formatted as an unambiguous string, not a date literal, and must contain only years, months, days, hours, and minutes -- no seconds. 

    "[ReceivedTime]" is a valid property to use. Look at the Object Browser for any Outlook item to see what properties are available for that type of item.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
     
     
    "TJoubert" <=?utf-8?B?VEpvdWJlcnQ=?=> wrote in message news:41d941ec-5815-4769-bda5-9187d133528b...

    Thanks for feedback. However the issue is not solved with what you have proposed. I am presently running tests on Inbox folder, using a filter like below (I am supplying today's date for comparison):

    searchFilter = "[ReceivedTime] >= '2012/3/6 00:00:00' AND [ReceivedTime] <= '2012/3/6 23:59:59'"

    The above filter still fails.

    Questions for which I cannot find any answer in MSDN's massive library:

    1) Is there a "ReceivedTime" attribute that can be used in a filter statement? If not, what are the filter attributes for Received Date/Time of the email and Sent Date/Time of the email?

    2) Does the date format depend on the local date/time settings or is there a universal format that Outlook Object Model supports? If it depends on local settings, will DateTime.ToShortDateString() method work?

    Thanks for any feedback that you may provide. 

    Regards

    Terence


    Ken Slovak MVP - Outlook
    • Marked as answer by TJoubert Tuesday, March 6, 2012 5:20 PM
    Tuesday, March 6, 2012 4:31 PM
    Moderator
  • Ken, my last post was replying to DamianD's reply to my original post. I had written it before seeing your post.

    Thanks for the article.  It has given me a lot of tips. I managed to get it to work in VB.NET using the following statement:

    "[ReceivedTime] >= '" & Format(DateTime.Now, "ddddd") & " 12:00 AM' AND [ReceivedTime] <= '" & Format(DateTime.Now, "ddddd") & " 11:59 PM'"

    Regards

    Terence

    • Marked as answer by TJoubert Tuesday, March 6, 2012 5:21 PM
    Tuesday, March 6, 2012 5:08 PM
  • Good, I'm glad that article helped. Filtering on dates in Outlook code is a bit obscure.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
     
     
    "TJoubert" <=?utf-8?B?VEpvdWJlcnQ=?=> wrote in message news:52eced04-08c5-40fd-b717-2381fb22c7a7...

    Ken, my last post was replying to DamianD's reply to my original post. I had written it before seeing your post.

    Thanks for the article.  It has given me a lot of tips. I managed to get it to work in VB.NET using the following statement:

    "[ReceivedTime] >= '" & Format(DateTime.Now, "ddddd") & " 12:00 AM' AND [ReceivedTime] <= '" & Format(DateTime.Now, "ddddd") & " 11:59 PM'"

    Regards

    Terence


    Ken Slovak MVP - Outlook
    Tuesday, March 6, 2012 5:23 PM
    Moderator