我创建了一些与相关电子邮件中出现的关键字相同的邮件类别,并希望自动将这些类别应用于它们。当然,我可以为每个类别单独手动创建过滤器,但这是一项相当繁琐的任务,每次创建新类别时我都必须记住重复这一操作。
因此,我想知道如何设置 Outlook(目前为 2007 版,但预计很快会更新至 2010 版),以便
for each incoming mail:
for each category:
if the mail (header or body) contains the category:
assign that category to the mail
答案1
创建以下宏并将其用作所有传入邮件的过滤器:
Sub CategorizeByKeywords(Item As Outlook.MailItem)
Dim objCats As Categories
Dim objCat As Category
Set objCats = Application.GetNamespace("MAPI").Categories
If objCats.Count > 0 Then
For Each objCat In objCats
If (InStr(Item.Subject, objCat.Name) > 0) Or _
(InStr(Item.Body, objCat.Name) > 0) Then
If Item.Categories = Null Then
Item.Categories = objCat.Name
Else
Item.Categories = objCat.Name & "," & Item.Categories
End If
End If
Next
End If
Item.Save
End Sub
Sub CategorizeSelectedMessages()
Dim objItem As Outlook.MailItem
For Each objItem In Application.ActiveExplorer.Selection
Call CategorizeByKeywords(objItem)
Next
End Sub