Hello all and thank you for your support,
Please, anyone knows how to get both cases where email is "something@emailprovider.com" and "Name Surname"?
I'm using the following filter
; email Search Parameters
lookForRecipient := ReceiverEmail
strQuery := "urn:schemas:httpmail:displayto like '%" lookForRecipient "%'"
emailScopeFolder := "\\myemail@outlook.com\inbox\myFolder\mysubFolder"
searchSubfolders := True
searchObject := this.outlook.AdvancedSearch(emailScopeFolder, strQuery, searchSubfolders)
; Wait until Outlook's AdvancedSearch returns AdvancedSearchComplete
oSearchEvents := new SearchEvents
ComObjConnect(this.outlook, oSearchEvents)
while (!oSearchEvents.SearchComplete) {
ToolTip, % "Wait. Search in progress"
}
; Get final results. Sort the results by time received time, selecting the newest (latest) one
searchResults := searchObject.Results
countResults := searchResults.Count()
searchResults.Sort("[ReceivedTime]", true)
latestSentEmail := searchResults.GetFirst()
Obs, elsewhere in the code, I have the class SearchEVents defined
class SearchEvents
{
AdvancedSearchComplete(searchObject)
{
ToolTip, % "Wait. SearchEvents.AdvancedSearchComplete() is in progress"
Sleep, 200
this.SearchComplete := true
}
}
And it works to find latest email sent. But not always.
If the email "ReceiverEmail" is something like "abc@hotmail.com"
So, using displayTo as namespace, it finds the email only if the email really appears in the To Field. If instead of the email there is a "name", the email is not found!
How can I search in "To" field?
Obs: I tried the options below without success.
Or, in text format,
;strQuery := "urn:schemas:httpmail:displayto like '%" lookForRecipient "%'" ; WORKS, but only if ToField is something@emailprovider.com
;strQuery := "urn:schemas:httpmail:to like '%" lookForRecipient "%'" ; no result
;strQuery := "urn:schemas:httpmail:namespace:to like '%" lookForRecipient "%'" ; no result
;strQuery := "urn:schemas:httpmail:reply-to like '%" lookForRecipient "%'" ; no result
;strQuery := "urn:schemas:httpmail:reply_to like '%" lookForRecipient "%'" ; no result
;strQuery := "urn:schemas:httpmail:reply_by like '%" lookForRecipient "%'" ; no result
;strQuery := "urn:schemas:httpmail:reply-by like '%" lookForRecipient "%'" ; error
;strQuery := "urn:schemas:mailheader:to like '%" lookForRecipient "%'" ; no result
;strQuery := "urn:schemas:mailheader:in-reply-to like '%" lookForRecipient "%'" ; no result
;strQuery := "urn:schemas:mailheader:reply-to like '%" lookForRecipient "%'" ; no result
strQuery := "urn:schemas:mailheader:return-receipt-to like '%" lookForRecipient "%'" ; no result
Please, anyone knows how to get both cases where email is "something@emailprovider.com" and "Name Surname"?
Thank you very much!
=============================== @niton
I have tried Items.Restrict(strFiler) as the link you sent without success.
subboxMail :=
this.mailBox.Folders(this.emailBox).Folders(this.emailSubBox)
strFilter := "@SQL=" Chr(34) "http://schemas.microsoft.com/mapi/proptag/0x0076001E" Chr(34) " like '%" lookForRecipient "%'"
restrictResults := subboxMailItems.Restrict(strFilter)
restrictResultsCount := restrictResults.Count
msgbox, % "searchedSubFolderCount = " searchedSubFolderCount "`n`n strFilter = " strFilter "`n`n restrictResultsCount = " restrictResultsCount
The message box returns searchSubfolderCount = 2000+ (the exact number of emails in the folder) but restrictResultCount = 0
Obs, and if I use two times the double quotes (") it raises an error.