Skip to content

Instantly share code, notes, and snippets.

@HarryZ10
Created March 3, 2024 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HarryZ10/77d43f2a2e46679b4ce14f37b9b513f1 to your computer and use it in GitHub Desktop.
Save HarryZ10/77d43f2a2e46679b4ce14f37b9b513f1 to your computer and use it in GitHub Desktop.
Gmail Parser
function pullEmailData() {
// Get the current spreadsheet
var ss = SpreadsheetApp.getActiveSheet();
// Array of labels to iterate through
var labels = ["B---University/Open Job Applications"];
for (var i = 0; i < labels.length; i++) {
var label = GmailApp.getUserLabelByName(labels[i]);
// Get all of the threads in the label
var threads = label.getThreads();
// Loop through the threads and get all of the messages in each thread
for (var j = 0; j < threads.length; j++) {
var messages = threads[j].getMessages();
for (var k = 0; k < messages.length; k++) {
var to = messages[k].getTo();
var from = messages[k].getFrom();
var sub = messages[k].getSubject();
var date = messages[k].getDate();
var important = messages[k].isInPriorityInbox();
var starred = messages[k].isStarred();
var body = messages[k].getPlainBody();
// Append the message information to the spreadsheet
ss.appendRow([to, from, sub, date, important, starred, body.substring(0, 500)]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment