【问题标题】:How to filter e-mails from a specific domain and number of receivers?如何过滤来自特定域和接收者数量的电子邮件?
【发布时间】:2022-06-26 06:16:54
【问题描述】:

我想使用 DASL 过滤器来:

  1. 排除收件人的特定域(例如,@test.com)

  2. 将结果限制为一对一的电子邮件(仅限一位收件人)。

首先我想到了这个查询:

"urn:schemas:httpmail:displayto" LIKE '%@%'AND NOT "urn:schemas:httpmail:displayto" LIKE '%@test.com'

但它不起作用,我在几封电子邮件的接收者列表中仍有@test.com 的电子邮件。

对于第二点,我不知道如何限制为一个收件人。

提前致谢。

【问题讨论】:

    标签: vba outlook


    【解决方案1】:

    使用以下运算符<>,表示搜索字符串中不相等:

    "urn:schemas:httpmail:displayto"  LIKE '%@%' AND "urn:schemas:httpmail:displayto"  <> '%@test.com'
    

    【讨论】:

    • 我仍然收到电子邮件,其中必然包含一个或多个不同于“test.com”的接收域,但有时也包含“test.com”。我认为它只是将结果限制为“一个或多个电子邮件接收者必须具有与 test.com 不同的域”,而不是“所有接收者必须具有与 test.com 不同的域”。
    • 听起来你需要使用单个条件"urn:schemas:httpmail:displayto" &lt;&gt; '%@test.com'
    • 我仍然有收件人为“@test.com”的电子邮件,但他们在收件人列表中显示了他们的名字和姓氏。也许过滤器不适用于这种特殊情况
    • 您可以在 Outlook UI 中设置过滤器,然后在代码中重复使用。
    【解决方案2】:

    两个单独的过滤器更容易弄清楚。

    Private Sub FindMail_RestrictDomainTest()
        
        Dim olFolder As Folder
            
        Dim strFilter As String
        Dim foundItems As Items
        Dim i As Long
        
        Set olFolder = Session.GetDefaultFolder(olFolderInbox)
        
        ' You could generate two separate working filters
        
        ' Filter 1
        strFilter = "@SQL=" & "urn:schemas:httpmail:displayto" & " Like '" & "%@%" & "'"
        Debug.Print "strFilter: " & strFilter
        
        Set foundItems = olFolder.Items.Restrict(strFilter)
        Debug.Print "foundItems.Count: " & foundItems.count
        
        ' Filter 2
        strFilter = "@SQL=" & "NOT urn:schemas:httpmail:displayto" & " Like '" & "%@test.com" & "'"
        Debug.Print "strFilter: " & strFilter
        
        ' Filter      ** foundItems **      not olFolder.Items
        Set foundItems = foundItems.Restrict(strFilter)
        Debug.Print "foundItems.Count: " & foundItems.count
        
        For i = 1 To foundItems.count
        
            If TypeOf foundItems(i) Is mailItem Then
                With foundItems(i)
                    Debug.Print i & " - " & .ReceivedTime
                    Debug.Print "      " & .subject
                    Debug.Print "      " & .To
                End With
            End If
            
        Next i
        
        
        ' Combined filters. There is no reason to do so.
        strFilter = "@SQL=" & "urn:schemas:httpmail:displayto" & " Like '" & "%@%" & "' AND " & _
          "NOT urn:schemas:httpmail:displayto" & " Like '" & "%@test.com" & "'"
        Debug.Print "strFilter: " & strFilter
        
        Set foundItems = olFolder.Items.Restrict(strFilter)
        Debug.Print "foundItems.Count: " & foundItems.count
        
        For i = 1 To foundItems.count
        
            If TypeOf foundItems(i) Is mailItem Then
                With foundItems(i)
                    Debug.Print i & " - " & .ReceivedTime
                    Debug.Print "      " & .subject
                    Debug.Print "      " & .To
                End With
            End If
            
        Next i
        
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2012-08-23
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 2020-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多