Skip to content

Instantly share code, notes, and snippets.

@rooreynolds
Last active June 2, 2022 20:09
Show Gist options
  • Save rooreynolds/57a5bee6f6938af7f65b0739c7604512 to your computer and use it in GitHub Desktop.
Save rooreynolds/57a5bee6f6938af7f65b0739c7604512 to your computer and use it in GitHub Desktop.
Gmail email stats (Google Sheets script)
function CountEmail() {
var starredEmails = GmailApp.search('is:starred');
var newunreadEmails = GmailApp.search('is:unread label:inbox');
var urgentEmails = GmailApp.search('label:urgent');
var waitingEmails = GmailApp.search('label:waiting-for');
var chaseEmails = GmailApp.search('label:chase');
var draftEmails = GmailApp.search('in:draft');
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var date = new Date();
sheet.appendRow([date,
starredEmails.length,
newunreadEmails.length,
urgentEmails.length,
waitingEmails.length,
chaseEmails.length,
draftEmails.length]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment