Managing a cluttered inbox can be challenging, especially when hundreds of emails arrive daily from various senders. How do you keep track of who sends you the most emails? How can you prioritize your responses more effectively? Introducing MailMetrics, a simple Gmail script that helps you monitor and count emails from each sender, giving you valuable insights into your communication patterns.
In this post, I’ll guide you through setting up MailMetrics using Google Apps Script to automate email tracking. Let’s dive into how you can create this useful tool and gain better control over your inbox.
Why Use MailMetrics?
Understanding who dominates your inbox can provide crucial insights into your email habits. With MailMetrics, you can:
- Identify Top Senders: Instantly see which contacts or organizations flood your inbox the most.
- Improve Inbox Management: Know which conversations demand your attention and which you can deprioritize.
- Clean Up Clutter: Spot overactive senders and unsubscribe or set up email filters as needed.
How to Set Up MailMetrics
MailMetrics uses Google Apps Script, a cloud-based platform designed for automating tasks across Google services like Gmail. This script fetches emails from your inbox, counts how many you’ve received from each sender, and logs the results.
Here’s how to get started:
Step 1: Create a Google Apps Script Project
- Head over to Google Apps Script and sign in with your Google account.
- Click on New Project.
- Name the project MailMetrics.
Step 2: Add the Script Code
Once inside the project editor, copy and paste the following code into the script editor:
function getEmailsCountPerSender() { var threads = GmailApp.getInboxThreads(); // Fetch inbox threads var sendersCount = {}; // Loop through each thread threads.forEach(function(thread) { var messages = thread.getMessages(); messages.forEach(function(message) { var sender = message.getFrom(); // Count emails per sender if (sendersCount[sender]) { sendersCount[sender]++; } else { sendersCount[sender] = 1; } }); }); // Log the results for (var sender in sendersCount) { Logger.log("Sender: " + sender + ", Count: " + sendersCount[sender]); } }
Step 3: Run the Script
- Save your project by clicking on the Save button.
- Click on the Run button to execute the script.
- Navigate to
View > Logsto see the email counts per sender.
You should now see a list of senders and how many emails they’ve sent you.
Step 4: Customize MailMetrics to Your Needs
Once you’ve got the basic script running, you can further enhance it to suit your workflow:
- Filter Emails: Modify the script to count only specific labels like “Work” or “Family” by using Gmail’s built-in filtering.
- Automated Reports: Set the script to send email reports with sender counts on a weekly or monthly basis.
- Visualization: Export the data to Google Sheets to create visual charts and graphs of your email activity.
Benefits of Using MailMetrics
MailMetrics provides you with the information you need to make smarter decisions about how you manage your emails. By knowing which senders take up the most space in your inbox, you can:
- Prioritize Important Conversations: Focus on emails from high-priority senders.
- Tidy Up Your Inbox: Identify and unsubscribe from newsletters or promotional emails that clutter your inbox.
- Streamline Email Workflow: Develop a better strategy for managing your email communication.

Leave a Reply