Email searching in Outlook
-
06 Maret 2012 9:55
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
Semua Balasan
-
06 Maret 2012 10:12
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.
-
06 Maret 2012 16:16ModeratorSee if this article helps: http://www.outlookcode.com/article.aspx?id=30
--
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 -
06 Maret 2012 16:25
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
-
06 Maret 2012 16:31Moderator
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- Ditandai sebagai Jawaban oleh TJoubert 06 Maret 2012 17:20
-
06 Maret 2012 17:08
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
- Ditandai sebagai Jawaban oleh TJoubert 06 Maret 2012 17:21
-
06 Maret 2012 17:23ModeratorGood, 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