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
- For a start, trigger VBA editor according to “How to Run VBA Code in Your Outlook“.
- 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 objMail.Save End If Next End Sub
- Next, open Inbox and go to “View” tab and click “View Settings”.
- In popup dialog, click “Group By”.
- Then, in the subsequent dialog box, uncheck “Automatically group according to arrangement”.
- After that, choose “User-defined fields in Inbox” from the dropdown list of “Select available fields from”.
- Later, select “Domain” in “Group items by”.
- Lastly, click a series of “OK” to save the changed view settings.
- 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.
Method 2: Count by Sender Domain Directly via VBA
- 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 Else objDictionary.Add strSenderDomain, 1 End If End If Next varSenderDomains = objDictionary.Keys varItemCounts = objDictionary.Items For i = LBound(varSenderDomains) To UBound(varSenderDomains) strMsg = varSenderDomains(i) & vbTab & varItemCounts(i) & vbCrLf & strMsg Next MsgBox "Inbox Email Count by Sender Domain: " & vbCrLf & vbCrLf & strMsg, vbInformation + vbOKOnly End Sub
- Eventually, press “F5” key button.
- At once, you’ll receive the message prompting of the email counts by sender domain, as shown in the screenshot below.
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.
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