My issue is that the first thread in my inbox is being displayed 45 times which is the number of messages in my inbox. What I need is the for loop to go through all the threads and gather all the information in the threads into a 2D array.
I know the issue is most likely with var message = threads[i].getMessages()[0]
but I'm not sure how to solve the problem.
This my code:
function TheaThreads(){ var SS =SpreadsheetApp.getActiveSpreadsheet(); var ThreadSheet = SS.getSheetByName("Threads"); var threads = GmailApp.getInboxThreads(); for (var i=0; i < threads.length; i++) { var message = threads[i].getMessages()[0], label = threads[i].getLabels(), //subject = message.getSubject(), //content = message.getPlainBody(), ident = message.getId(), emailfrom = message.getFrom(); if(label==null|| label== undefined|| label.length==0){ label="No Label"; } var threadArray = new Array(); for(i=0; i<threads.length; i++){ threadArray[i] = new Array(); threadArray[i][0]= ident; threadArray[i][1]= label; threadArray[i][2]= emailfrom; Logger.log(threadArray); } }