如何设置仅匹配名字的Outlook消息规则?


0

我从我们的票务系统收到大量垃圾邮件,其中大部分都是我忽略的,但偶尔有人会提到“西蒙你能看一下这个吗?”

我想将它们过滤到子文件夹中,如果它包含单词'simon',但不幸的是每条消息都以类似的方式结束

“消息发送给用户John Smith和Simon Johnson”

因此,如果我添加一条规则来检测“Simon”,它会将每封电子邮件移动到该文件夹​​中。

如果我排除'西蒙约翰逊',那么它不会发送任何电子邮件。

有没有办法让它需要> 1个西蒙的实例,或者只匹配西蒙而忽略西蒙约翰逊?

Answers:


1

一个 VBA 像下面这样的脚本可以完成这项工作:

Option Explicit

Sub DoubleSimonMessageRule(newMail As Outlook.mailItem)
    Dim a() As String          '  we convert the mail body to an array of string
    Dim EntryID As String
    Dim StoreID As Variant
    Dim mi As Outlook.mailItem
    Dim dest As String
    Dim destFldr As Outlook.Folder
    Dim I As Integer
    Dim iMatch As Integer

    Const pattern = "Simon"
    Const dest1 = "Simon1"     '  destination folder for 1 match
    Const destAny = "SimonAny" '  destination folder for 2+ matches

    On Error GoTo ErrHandler


    '  we have to access the new mail via an application reference
    '  to avoid security warnings
    EntryID = newMail.EntryID
    StoreID = newMail.Parent.StoreID

    Set mi = Application.Session.GetItemFromID(EntryID, StoreID)

    a = Split(mi.body, vbCrLf)
    iMatch = 0
    For I = LCase(a) To UCase(a)
        If InStr(1, a(I), pattern, vbTextCompare) Then
            iMatch = iMatch + 1
        End If
    Next I

    If iMatch < 1 Then
        '  this should not happen, provided our rule is configured properly
        Err.Raise 1, , "No " & pattern & " in Mail"
    ElseIf iMatch = 1 Then
        dest = dest1
    ElseIf iMatch > 1 Then
        dest = destAny
    End If

    Set destFldr = Application.GetNamespace("MAPI").Folders(dest)
    mi.Move destFldr
    ' mi.Delete    '  not sure about this!
    Set mi = Nothing

    Exit Sub

ErrHandler:
    Debug.Print Err.Description
    Err.Clear
    On Error GoTo 0
End Sub

使用Outlook Rule Assistant为其邮件正文中包含“Simon”的传入邮件调用此脚本。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.