Skip to content

Instantly share code, notes, and snippets.

@mhawksey
Last active March 27, 2020 20:08
Show Gist options
  • Save mhawksey/9f94d00099502ae401ce346fd619a25f to your computer and use it in GitHub Desktop.
Save mhawksey/9f94d00099502ae401ce346fd619a25f to your computer and use it in GitHub Desktop.
Short Google Apps Script snippet that pushes from:, subject and date to a Google Sheet (designed to be triggered frequently). I use the snippet to collect votes sent via email
function myFunction() {
try {
var out = [];
if (GmailApp.getInboxUnreadCount() > 0 ){
var threads = GmailApp.getInboxThreads();
for (var i = 0; i < threads.length; i++) {
out.push([threads[i].getMessages()[0].getFrom(), threads[i].getFirstMessageSubject(), threads[i].getMessages()[0].getDate()]);
threads[i].moveToArchive();
}
var doc = SpreadsheetApp.openById('1iu3tAW4u4u9oq4QAk6mf0ItcKWUNMGZpdAYT3es2OI8');
var sheet = doc.getSheetByName('Email_votes');
sheet.insertRows(2, out.length);
sheet.getRange(2, 1, out.length, 3).setValues(out);
}
} catch(e) {
MailApp.sendEmail('[email protected]', 'LTAwards email fail', JSON.stringify(e, null, "\t"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment