I copied this function from somewhere on the web. My goal is to import the body of specifically labeled emails in my gmail account to a google spreadsheet. While I'm not completely inept when it comes to coding, I'm not familiar with this stuff.
Some details that may be relevant: Each of these Emails I am trying to import are NOT conversations, they are a single email received, no response and no earlier messages in the thread. I want the entire body of each Email placed in a single cell in the spreadsheet.
As it is, only the subject is being placed in my spreadsheet. How can I get it to bring the body, as well? I feel like it's being placed in the array, but when looping the setValue it gets skipped.
Much love, folks!
Code:
function getMessagesWithLabel() {
var destArray = new Array();
var threads = GmailApp.getUserLabelByName('abc').getThreads(1,10);
for(var n in threads){
var msg = threads[n].getMessages();
var destArrayRow = new Array();
destArrayRow.push('thread has '+threads[n].getMessageCount()+' messages');
for(var m in msg){
destArrayRow.push(msg[m].getSubject());
}
destArray.push(destArrayRow);
}
Logger.log(destArray);
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getActiveSheet();
if(ss.getLastRow()==0){sh.getRange(1,1).setValue('getMessagesWithLabel() RESULTS')};
sh.getRange(ss.getLastRow()+1,1,destArray.length,destArray[0].length).setValues(destArray)
}