How to Auto Color Categorize Outlook Emails based on Whether Senders are Known or Unknown

If you want to distinguish between the emails from known and unknown senders by color categories, you can use the means introduced in this post. It will use Outlook VBA to auto color categorize the incoming emails based on the senders.

As we all know, Outlook comes packed with a native classification feature – Color Categories. Undoubtedly, it indeed plays a good role in managing and organizing a great amount of Outlook items, such as myriad emails. Therefore, many people prefer to use this feature to distinguish the different kinds of messages, such as differentiating emails from known and unknown senders. Focused on this issue, here we will expose a quick method, which can auto categorize and distinguish such emails via VBA.

Auto Color Categorize Outlook Emails based on Sender

Auto Color Categorize Emails based on Whether Senders are Known or Unknown

  1. In the first place, launch your Outlook program properly.
  2. After entering the main Outlook interface, press “Alt + F11” key shortcuts.
  3. Then you will get into the “Microsoft Visual Basic for Applications” window.
  4. Next you can copy and paste the following codes into “ThisOutlookSession” project window.
Public WithEvents objItems As Outlook.Items

Private Sub Application_Startup()
    Set objItems = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub objItems_ItemAdd(ByVal Item As Object)
    Dim objMail As Outlook.MailItem
    Dim strSenderEmailAddress As String
    Dim objContacts As Outlook.Items
    Dim objContact As Object
    Dim objFoundContact As Outlook.ContactItem
    Dim strFilter As String
    Dim strContactCategory As String
    Dim i As Long
    If TypeOf Item Is MailItem Then
       Set objMail = Item
       strSenderEmailAddress = objMail.SenderEmailAddress
       Set objContacts = Outlook.Application.Session.GetDefaultFolder(olFolderContacts).Items
       For Each objContact In objContacts
           If TypeOf objContact Is ContactItem Then
              For i = 1 To 3
                  strFilter = "[Email" & i & "Address] = " & strSenderEmailAddress
                  Set objFoundContact = objContacts.Find(strFilter)
                  'Check if the sender exists in your contacts folder
                  If Not (objFoundContact Is Nothing) Then
                     strContactCategory = objFoundContact.Categories
                     'If the corresponding contact has no category
                     'Assign the "Known" category to the email
                     If strContactCategory = "" Then
                        objMail.Categories = "Known"
                        'If the contact has, directly use its category
                        objMail.Categories = strContactCategory
                     End If
                     Exit For
                  End If
             Next i
            'If the sender doesn't exist in the Contacts folder
            'Assign the "Unknown" category to the email
            If objFoundContact Is Nothing Then
               objMail.Categories = "Unknown"
            End If
          End If
       Next objContact
   End If
End Sub

VBA Codes - Auto Color Categorize Outlook Emails based on Whether Senders are Known or Unknown

  1. After that, you should proceed to sign the new VBA project.
  2. Later change your Outlook macro setting, permitting digitally signed macros.
  3. Finally you can restart Outlook to activate the macro.

From now on, Outlook will automatically categorize the new incoming emails based on their senders by the following rules:

  1. If the sender exists in your Contacts folder and the according contact has a specific color category, the email will be categorized with the same color.
  2. If the corresponding contact hasn’t been color categorized, only the “Known” color category will be assigned to the email.
  3. If the sender doesn’t exist in Contacts folder, the incoming email will be categorized with “Unknown”.Emails in Different Color Categories

Tackle Unexpected Outlook Problems

It is a common case that Outlook suddenly crash without any omens. Confronted with such a situation, you should calm down right away and then check if PST file is intact or not. If unfortunately PST file gets corrupt, you can try to recover PST data from your regular backups. But if no backups, you have no choice but to use an experienced repair tool, such as DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupt SQL Server and outlook repair software products. For more information visit

Comments are closed.