Skip to content

Instantly share code, notes, and snippets.

@alaq
Created May 18, 2017 21:14
Show Gist options
  • Save alaq/e8cf8185d483ba07f3c484e29d3d6ab5 to your computer and use it in GitHub Desktop.
Save alaq/e8cf8185d483ba07f3c484e29d3d6ab5 to your computer and use it in GitHub Desktop.
When run, will return in a spreadsheet the number of emails in your inbox, as well as the number of emails received the previous day. Run it with a daily trigger at 1am.
function GmailEmails() {
var InboxThread = GmailApp.getInboxThreads().length;
var today = new Date();
var year = today.getYear();
var month = today.getMonth() + 1;
var day = today.getDate();
var day1 = day - 1;
var day2 = day;
var yesterdayThreads = GmailApp.search('-from:me after:' +year +'/'+month +'/'+day1 + ' before:' +year +'/'+month +'/'+day2);
var threadCount = yesterdayThreads.length;
var gmailSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Gmail");
gmailSheet.appendRow([new Date(),InboxThread,threadCount]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment