I am trying to create a code that parses through a gmail and extracts the subject line of specifically labeled emails and automatically exports the data into a google spreadsheet.
var sheet = SpreadsheetApp.getActiveSheet();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
function getEmails() {
var label = GmailApp.getUserLabelByName("Reservation confirmed");
var threads = label.getThreads();
var row = 2;
for (var i = 0; i < threads.length; i++) {
var messages=threads[i].getMessages();
for (var m=0; m < messages.length; m++) {
sheet.getRange(row,1).setValue(messages[m].getPlainBody());
row++;
}
}
}
function onOpen() {
var menuEntries = [ {name: "Load Emails", functionName: "getEmails"} ];
spreadsheet.addMenu("Email", menuEntries);
}
This current code I have takes the body of labeled emails but for some reason I cannot alter it so that it only takes the subject line.