How to have Outlook automatically assign existing categories when they appear in incoming mails?

0

I created some mail categories identical to keywords that appear in related emails and would like to have the categories applied automatically to them. Surely I could manually create filters for each category individually, but this is a rather tedious task that I'd have to remember repeating every time I create a new category.

Therefore, I'd like to know how to set up Outlook (currently 2007, though an update to 2010 is supposed to happen soon) such that

for each incoming mail:
    for each category:
        if the mail (header or body) contains the category:
            assign that category to the mail

Tobias Kienzler

Posted 2014-08-22T07:37:29.910

Reputation: 3 262

Answers

0

Create the following macro and use that as filter on all incoming mail:

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

Tobias Kienzler

Posted 2014-08-22T07:37:29.910

Reputation: 3 262