-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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