Skip to content

Instantly share code, notes, and snippets.

@schlos
Forked from mhawksey/sendvotes.gs
Created August 24, 2018 20:43
Show Gist options
  • Save schlos/229a01078995055c8dd5364651cd88a1 to your computer and use it in GitHub Desktop.
Save schlos/229a01078995055c8dd5364651cd88a1 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('martin.hawksey@alt.ac.uk', '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