微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么 (Outlook vba api) AdvancedSearch 在搜索发送给某人的电子邮件时返回错误的电子邮件结果?

如何解决为什么 (Outlook vba api) AdvancedSearch 在搜索发送给某人的电子邮件时返回错误的电子邮件结果?

大家好,感谢大家的支持

请问,有人知道如何同时获取电子邮件是“something@emailprovider.com”和“姓名”的两种情况吗?

我正在使用以下过滤器

; 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,在代码的其他地方,我定义了 SearchEVents 类

class SearchEvents
{
    AdvancedSearchComplete(searchObject)
    {
        ToolTip,% "Wait. SearchEvents.AdvancedSearchComplete() is in progress"
        Sleep,200
        this.SearchComplete := true
    }
}

它可以找到最新发送的电子邮件。 但并非总是如此。

如果电子邮件“ReceiverEmail”类似于“abc@hotmail.com”

这会被发现

enter image description here

但这不会被发现

enter image description here

因此,使用 displayTo 作为命名空间,只有当电子邮件确实出现在“收件人”字段中时,它才会找到电子邮件。如果不是电子邮件而是“名称”,则找不到电子邮件

如何在“收件人”字段中搜索

Obs:我尝试了以下选项但没有成功。

enter image description here

或者,以文本格式,

;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

请问,有人知道如何同时获取电子邮件是“something@emailprovider.com”和“姓名”的两种情况吗?

非常感谢!

================================ @尼顿

我已尝试将 Items.Restrict(strFiler) 作为您发送的链接但没有成功。

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

消息框返回 searchSubfolderCount = 2000+(文件夹中电子邮件的确切数量) 但 限制结果计数 = 0

enter image description here

Obs,如果我使用双引号 (") 两次,则会引发错误

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。