Search code examples
google-apps-scriptgmail

Google Apps Script: How to remove empty Gmail labels?


With Google Apps Script, is it possible to remove empty (unused) Gmail labels?


Solution

  • Certainly, first use GmailApp.getUserLabels() to retrieve all the labels, then loop over them and use getThreads() to determine if a given label is empty, and finally use deleteLabel() to remove empty ones.

    See:

    https://developers.google.com/apps-script/reference/gmail/gmail-app

    https://developers.google.com/apps-script/reference/gmail/gmail-label