2021年4月3日星期六

How do I gather data from email thread in Google Apps Scripts? The same thread is repeated for the length of my inbox

I'm building a program in Google Apps Scripts that gathers the from email, label and the ID of the inbox threads. Currently, I have 2 for loops iterating through the messages in order to gather the information from the threads and place them into a 2D array. My end goal is to take the labels in the email threads gather the emails with a specific label, and any email that is not labeled, the program will label using the thread ID. The issue I'm having is that only the first thread is outputted about 45 times which is the length of my inbox. Im not sure whether I'm using an incorrect method, or there is something else wrong with my code that is preventing each thread from being read once. If you run the program the i in the first for loop iterates only through the first element and I'm not sure why.

 function TheaThreads(){    // var label, ident, emailfrom = [];    var SS =SpreadsheetApp.getActiveSpreadsheet();    var ThreadSheet = SS.getSheetByName("Threads");    var threads = GmailApp.getInboxThreads();       for (var i=0; i < threads.length; i++) {      for (var j = 0; j < threads[i].getMessages().length; j++){      Logger.log(i);      var message = threads[i].getMessages()[j],      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";      }     }     // lab.push(label);     // ide.push(ident);     // ema.push(emailfrom);       var csNames = new Array();     for(i=0; i<threads.length; i++){       csNames[i] = new Array();       csNames[i][0]= ident;       csNames[i][1]= label;       csNames[i][2]=emailfrom;       Logger.log( ident);   }  
https://stackoverflow.com/questions/66937421/how-do-i-gather-data-from-email-thread-in-google-apps-scripts-the-same-thread-i April 04, 2021 at 10:03AM

没有评论:

发表评论