2 Smart Means to Count Inbox Emails by Sender Domain in Your Outlook

If you need to count the inbox emails by sender domain, it is too stupid to figure out the domain of each email and then count one by one. It is highly suggested to utilize the 2 methods introduced in this article.

Perhaps you have received a great number of emails in Inbox. Thereby, now, you want to count them. Maybe not only do you want to get a total count, but also you would like to count the inbox emails by sender domain. Here we will introduce 2 methods to quickly get the counts by sender domain.

Method 1: Get Count after Grouping Emails by Sender Domain

  1. For a start, trigger VBA editor according to “How to Run VBA Code in Your Outlook“.
  2. Then, put the VBA code below into a module.
Sub GetSenderDomain()
    Dim objInboxItems As Outlook.Items
    Dim i As Long
    Dim objMail As Outlook.MailItem
    Dim objDomainProperty As Outlook.UserProperty
    Dim strSenderAddress, strSenderDomain As String
    Set objInboxItems = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Items
    For i = objInboxItems.Count To 1 Step -1
        If TypeOf objInboxItems(i) Is MailItem Then
           Set objMail = objInboxItems(i)
           Set objDomainProperty = objMail.UserProperties.Find("Domain", True)
           If objDomainProperty Is Nothing Then
              Set objDomainProperty = objMail.UserProperties.Add("Domain", olText, True)
           End If
           strSenderAddress = objMail.SenderEmailAddress
           strSenderDomain = Right(strSenderAddress, Len(strSenderAddress) - InStr(strSenderAddress, "@"))
           objDomainProperty.Value = strSenderDomain
        End If
End Sub

VBA Code - Get Sender Domain

  1. Next, open Inbox and go to “View” tab and click “View Settings”.
  2. In popup dialog, click “Group By”.
  3. Then, in the subsequent dialog box, uncheck “Automatically group according to arrangement”.
  4. After that, choose “User-defined fields in Inbox” from the dropdown list of “Select available fields from”.
  5. Later, select “Domain” in “Group items by”.Group Inbox Emails by Sender Domain
  6. Lastly, click a series of “OK” to save the changed view settings.
  7. Now, in Inbox, when hovering cursor above a group header, you can see the email count of the specific sender domain, like the following figure.Get Count in Email Group Header

Method 2: Count by Sender Domain Directly via VBA

  1. To begin with, in Outlook VBA editor, copy the following code into a module.
Sub CountInboxEmailsbySenderDomain()
    Dim objDictionary As Object
    Dim objInbox As Outlook.Folder
    Dim i As Long
    Dim objMail As Outlook.MailItem
    Dim strSenderAddress As String
    Dim strSenderDomain As String
    Dim varSenderDomains As Variant
    Dim varItemCounts As Variant
    Dim strMsg As String
    Set objDictionary = CreateObject("Scripting.Dictionary")
    Set objInbox = Outlook.Application.Session.GetDefaultFolder(olFolderInbox)
    For i = objInbox.Items.Count To 1 Step -1
        If objInbox.Items(i).Class = olMail Then
           Set objMail = objInbox.Items(i)
           strSenderAddress = objMail.SenderEmailAddress
           strSenderDomain = Right(strSenderAddress, Len(strSenderAddress) - InStr(strSenderAddress, "@"))
           If objDictionary.Exists(strSenderDomain) Then
              objDictionary(strSenderDomain) = objDictionary(strSenderDomain) + 1
              objDictionary.Add strSenderDomain, 1
           End If
        End If
    varSenderDomains = objDictionary.Keys
    varItemCounts = objDictionary.Items
    For i = LBound(varSenderDomains) To UBound(varSenderDomains)
        strMsg = varSenderDomains(i) & vbTab & varItemCounts(i) & vbCrLf & strMsg
    MsgBox "Inbox Email Count by Sender Domain: " & vbCrLf & vbCrLf & strMsg, vbInformation + vbOKOnly
End Sub

VBA Code - Count Inbox Emails by Sender Domain

  1. Eventually, press “F5” key button.
  2. At once, you’ll receive the message prompting of the email counts by sender domain, as shown in the screenshot below.Message Prompting Email Counts

Escape from PST Data Loss

Since Outlook PST file contains all the items in your Outlook, you definitely don’t want to lose it. Hence, you have to firstly back up the file at regular intervals. Also, you should know how to find and launch Scanpst to repair Outlook file. Of course, since the inbuilt tool is unable to make effects in many cases, you had better get hold of a powerful external 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 mdf recovery and outlook repair software products. For more information visit www.datanumen.com

Leave a Reply

Your email address will not be published. Required fields are marked *