|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Searching by To or From fields (Outlook 2003)I am trying to write a simple macro that will search for e-mails sent or received within the last 3 months to or from the given e-mail address. A common function when you want to find all mail communication related to some person. The search code is simple as in the examples: strF = Chr(34) + "urn:schemas:httpmail:to" + Chr(34) + " like '%O%'" Dim Scope As String Scope = "'" & Application.Session.GetDefaultFolder(olFolderInbox).FolderPath & "','" & Application.Session.GetDefaultFolder(olFolderSentMail).FolderPath & "'" Set sch = Application.AdvancedSearch(Scope, strF, True) I have come across the several rather strange problems: 1) search for "urn:schemas:httpmail:to" or "urn:schemas:mailheader:to" doesn't seem to be working. Search results are empty. I assume that there are some security settings that prevent the search from working right. The e-mails are in the specified folders and they can be found if I change "to" to "subject" and change the search parameter acccordingly. So it's definitely the problem of To header (or security). 2) does outlook support boolean expressions in search parameters? I.e. can I write something like urn:schemas:httpmail:from='from@a' OR urn:schemas:httpmail:to='to@z' AND some_sent_field > 11/11/2007 or it is better to select all recent mails and search for the addresses in each mail item? 3) how do I determine and express the Sent date for sent mails in my search filter? Thanks in advance. With best regards, Eugene Mayevski http://www.SecureBlackbox.com - the comprehensive component suite for network security 1) Try "urn:schemas:httpmail:displayto" instead.
2) Yes, just remember that the schema property name needs to be in quotation marks and use parentheses to group: ("urn:schemas:httpmail:from" = 'from@a' OR "urn:schemas:httpmail:displayto LIKE '%to@z5') AND "urn:schemas:httpmail:date" > '11/11/2007 12:00 AM') 3) Criteria for date searches need to be string literals with no seconds element. Remember that the Filter dialog and its SQL tab is your friend when you need to develop and test a string for AdvancedSearch. -- Show quoteSue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Eugene Mayevski" <mayev***@eldos.com> wrote in message news:eTqbUNBLIHA.3848@TK2MSFTNGP05.phx.gbl... > > I am trying to write a simple macro that will search for e-mails sent or > received within the last 3 months to or from the given e-mail address. A > common function when you want to find all mail communication related to some > person. > > The search code is simple as in the examples: > > strF = Chr(34) + "urn:schemas:httpmail:to" + Chr(34) + " like '%O%'" > Dim Scope As String > Scope = "'" & Application.Session.GetDefaultFolder(olFolderInbox).FolderPath > & "','" & Application.Session.GetDefaultFolder(olFolderSentMail).FolderPath > & "'" > Set sch = Application.AdvancedSearch(Scope, strF, True) > > > I have come across the several rather strange problems: > 1) search for "urn:schemas:httpmail:to" or "urn:schemas:mailheader:to" > doesn't seem to be working. Search results are empty. I assume that there > are some security settings that prevent the search from working right. The > e-mails are in the specified folders and they can be found if I change "to" > to "subject" and change the search parameter acccordingly. So it's > definitely the problem of To header (or security). > 2) does outlook support boolean expressions in search parameters? I.e. can I > write something like > > urn:schemas:httpmail:from='from@a' OR urn:schemas:httpmail:to='to@z' AND > some_sent_field > 11/11/2007 > > or it is better to select all recent mails and search for the addresses in > each mail item? > > 3) how do I determine and express the Sent date for sent mails in my search > filter? Hello!
You wrote on Mon, 26 Nov 2007 14:13:53 -0500: SMM> 1) Try "urn:schemas:httpmail:displayto" instead. Thank you. Unfortunately this doesn't always work because displayto is the text, and this text is not always equal to the e-mail address. Sometimes outlook displays the name from the address book instead of the e-mail and this breaks the search :( SMM> 2) Yes, just remember that the schema property name needs to be in SMM> quotation marks and use parentheses to group: Great, thank you! SMM> ("urn:schemas:httpmail:from" = 'from@a' OR SMM> "urn:schemas:httpmail:displayto LIKE '%to@z5') AND SMM> "urn:schemas:httpmail:date" > '11/11/2007 12:00 AM') SMM> 3) Criteria for date searches need to be string literals with no SMM> seconds element. Remember that the Filter dialog and its SQL tab is SMM> your friend when you need to develop and test a string for You must be referring to Outlook 2007, aren't you? I checked Outlook 2003 and it doesn't have SQL tab. I will try to install Outlook 2007 and play with it, maybe this will help with To: search as well. Thanks again. With best regards, Eugene Mayevski http://www.SecureBlackbox.com - the comprehensive component suite for network security 1) Did you actually try it? In my testing, it finds items with the specificed email address in the To field.
3) No, Outlook 2003 also has a SQL tab on the Filter dialog for a custom view. -- Show quoteSue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Eugene Mayevski" <mayev***@eldos.com> wrote in message news:Oy96WKGMIHA.6108@TK2MSFTNGP03.phx.gbl... > Hello! > You wrote on Mon, 26 Nov 2007 14:13:53 -0500: > > SMM> 1) Try "urn:schemas:httpmail:displayto" instead. > > Thank you. Unfortunately this doesn't always work because displayto is the > text, and this text is not always equal to the e-mail address. Sometimes > outlook displays the name from the address book instead of the e-mail and > this breaks the search :( > > SMM> 2) Yes, just remember that the schema property name needs to be in > SMM> quotation marks and use parentheses to group: > > Great, thank you! > > SMM> ("urn:schemas:httpmail:from" = 'from@a' OR > SMM> "urn:schemas:httpmail:displayto LIKE '%to@z5') AND > SMM> "urn:schemas:httpmail:date" > '11/11/2007 12:00 AM') > > SMM> 3) Criteria for date searches need to be string literals with no > SMM> seconds element. Remember that the Filter dialog and its SQL tab is > SMM> your friend when you need to develop and test a string for > > You must be referring to Outlook 2007, aren't you? I checked Outlook 2003 > and it doesn't have SQL tab. > I will try to install Outlook 2007 and play with it, maybe this will help > with To: search as well. Thanks again. Hello!
You wrote on Mon, 26 Nov 2007 14:47:24 -0500: SMM> 1) Did you actually try it? In my testing, it finds items with the specificed email address in the To field. Yes, I did before the first post. 3) No, Outlook 2003 also has a SQL tab on the Filter dialog for a custom view. Oh, I see. I will try this now. With best regards, Eugene Mayevski http://www.SecureBlackbox.com - the comprehensive component suite for network security It worked for me once, but now it's not working. :( I'll investigate further.
-- Show quoteSue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Eugene Mayevski" <mayev***@eldos.com> wrote in message news:eG%23r5fGMIHA.4688@TK2MSFTNGP06.phx.gbl... 1) Try "urn:schemas:httpmail:displayto" instead. > Hello! > You wrote on Mon, 26 Nov 2007 14:47:24 -0500: > > SMM> 1) Did you actually try it? In my testing, it finds items with the > specificed email address in the To field. > > Yes, I did before the first post. "Eugene Mayevski" <mayev***@eldos.com> wrote in message news:Oy96WKGMIHA.6108@TK2MSFTNGP03.phx.gbl... > > Thank you. Unfortunately this doesn't always work because displayto is the > text, and this text is not always equal to the e-mail address. Sometimes > outlook displays the name from the address book instead of the e-mail and > this breaks the search :( > "Sue Mosher [MVP-Outlook]" <sue***@outlookcode.com> wrote in message news:uH5FFCGMIHA.4712@TK2MSFTNGP04.phx.gbl... Show quote "Eugene Mayevski" <mayev***@eldos.com> wrote in message news:eTqbUNBLIHA.3848@TK2MSFTNGP05.phx.gbl... > > I am trying to write a simple macro that will search for e-mails sent or > received within the last 3 months to or from the given e-mail address. A > common function when you want to find all mail communication related to some > person. > > The search code is simple as in the examples: > > strF = Chr(34) + "urn:schemas:httpmail:to" + Chr(34) + " like '%O%'" > Dim Scope As String > Scope = "'" & Application.Session.GetDefaultFolder(olFolderInbox).FolderPath > & "','" & Application.Session.GetDefaultFolder(olFolderSentMail).FolderPath > & "'" > Set sch = Application.AdvancedSearch(Scope, strF, True) > > > I have come across the several rather strange problems: > 1) search for "urn:schemas:httpmail:to" or "urn:schemas:mailheader:to" > doesn't seem to be working. Search results are empty. I assume that there > are some security settings that prevent the search from working right. The > e-mails are in the specified folders and they can be found if I change "to" > to "subject" and change the search parameter acccordingly. So it's > definitely the problem of To header (or security). this is why I don't like AdvancedSearch.
-- Show quoteBest regards Michael Bauer - MVP Outlook Synchronize Color Categories & Ensure that Every Item Gets Categorized: <http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6> Am Mon, 26 Nov 2007 15:55:37 -0500 schrieb Sue Mosher [MVP-Outlook]: > It worked for me once, but now it's not working. :( I'll investigate further. Hello!
You wrote on Mon, 26 Nov 2007 15:55:37 -0500: SMM> It worked for me once, but now it's not working. :( I'll investigate SMM> further. The strangest thing is that it doesn't work from the script only. When the same is used from the dialog, it works. I played with displayto again and ensured that the above results are consistent. With best regards, Eugene Mayevski http://www.SecureBlackbox.com - the comprehensive component suite for network security |
|||||||||||||||||||||||