如何在 Outlook 2007 中仅保留具有给定主题的最新消息?

如何在 Outlook 2007 中仅保留具有给定主题的最新消息?

我们有一个自动系统,可以通过电子邮件发送更新。这很好,对我来说这是有用的信息。我更希望只看到最新的更新,其余的则被丢弃。也就是说,给出以下列表

在此处输入图片描述

我只希望 34022 更新的选定版本保留在我的文件夹中。我在规则中搜索了好几遍,但似乎没有找到符合要求的。

有没有办法可以(自动)删除我不想要的?

答案1

使用一些 VBA。涉及删除时,彻底测试总是一个好主意。

Private Sub Application_NewMail()
' In ThisOutlookSession module

' see Create Outlook Rules Programmatically
' http://msdn.microsoft.com/en-us/library/aa163981(v=office.10).aspx

Dim olApp As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim olFld As Outlook.MAPIFolder
Dim objMail As Object

Set olApp = Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set olFld = olNs.GetDefaultFolder(olFolderInbox)

olFld.items.sort "Received", False
'Set objMail = olFld.items.GetFirst ' In Outlook 2003
Set objMail = olFld.items.GetLast ' In Outlook 2010

If TypeOf objMail Is MailItem Then

    If objMail.SenderEmailAddress = "Found in DetermineSenderEmailAddress" And _
        InStr(1, objMail.Subject, "Ticket:") Then

            DeleteOldStatus objMail

    End If

End If

Set objMail = Nothing
Set olFld = Nothing
Set olNs = Nothing
Set olApp = Nothing

End Sub

Sub DeleteOldStatus(objMail As MailItem)

Dim olFld As folder
Dim olNs As NameSpace
Dim olderMail As MailItem

Dim iDel As Long

Set olNs = Application.GetNamespace("MAPI")
Set olFld = olNs.GetDefaultFolder(olFolderInbox)

For iDel = olFld.items.Count To 1 Step -1

    Set olderMail = olFld.items(iDel)

    If olderMail.Subject = objMail.Subject Then

        If olderMail.ReceivedTime < objMail.ReceivedTime Then

            Debug.Print olderMail.Subject & " received  " & olderMail.ReceivedTime & " should be deleted."
            'olderMail.Delete ' Remove leading apostrophe to uncomment when ready

        End If

    End If

Next

Debug.Print "Done - " & objMail.Subject

End Sub


Sub DetermineSenderEmailAddress()

' open up an email then run

Dim currItem As MailItem
Set currItem = ActiveInspector.currentItem

' Copy the text from the immediate pane.
Debug.Print currItem.SenderEmailAddress

End Sub

编辑器和按钮帮助 -http://www.slipstick.com/developer/how-to-use-outlooks-vba-editor/

宏安全性应设置为中。

按钮帮助 -http://www.howto-outlook.com/howto/macrobutton.htm

编辑:修复了 InStr 行

相关内容