Site icon Being Software Craftsman (DFTBA)

Streamline Your Inbox with MailMetrics: Count Emails per Sender Automatically

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:


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

  1. Head over to Google Apps Script and sign in with your Google account.
  2. Click on New Project.
  3. 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

  1. Save your project by clicking on the Save button.
  2. Click on the Run button to execute the script.
  3. Navigate to View > Logs to 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:


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:

Exit mobile version