简体   繁体   English

如何从 Google Apps 脚本中的 email 线程收集数据? 我的收件箱长度重复相同的线程

[英]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.我正在 Google Apps 脚本中构建一个程序,该程序从 email、label 和收件箱线程的 ID 中收集信息。 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.目前,我有 2 个 for 循环遍历消息,以便从线程中收集信息并将它们放入 2D 数组中。 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. 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.我遇到的问题是,只有第一个线程被输出了大约 45 次,这是我收件箱的长度。 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.如果您运行程序,则第一个 for 循环中的 i 仅迭代第一个元素,我不知道为什么。

 function TheaThreads(){
  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";
    }
   }

   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);
 }

Remove消除

   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);

and, before并且,之前

for (var j = 0; j < threads[i].getMessages().length; j++){

add添加

var csNames = new Array();

and, after之后

 if(label==null|| label== undefined|| label.length==0){
label="No Label";

add添加

 csNames[j] = new Array();
 csNames[j][0]= ident;
 csNames[j][1]= label;
 csNames[j][2]=emailfrom;
 Logger.log( ident);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用google-api-nodejs-client nodejs在同一线程上发送电子邮件 - How do i send a email on same thread using google-api-nodejs-client nodejs 如何在我的Google Apps脚本/ Google表格HTML中包含脚本? - How do I include scripts in my Google Apps Script/Google Sheets HTML? Email 来自 Google Apps Scripts 的过滤结果 - Email the filter results from Google Apps Scripts 如何改进用于在 Google Apps 脚本中拖动多个单元格的脚本? - How do I improve my script for dragging multiple cells in Google Apps Scripts? 后台js脚本是否在Chrome操作系统应用程序的其他线程上运行? - Do background js scripts run on a different thread in Chrome OS apps? 如何使用 Google Apps 脚本中的按钮打开另一个页面? - How do I open another page with a button in Google Apps Scripts? Google Apps脚本-以字符串形式发送电子邮件 - Google Apps Scripts - Email as string 我如何使用谷歌应用程序脚本来修改我从谷歌分析中提取的数据? - How do i use google apps script to modify data that i pull from google analytics? 如何编辑范围? // 谷歌课堂控制谷歌应用脚​​本中学生访问权限范围 - How do I edit scopes? // Google Classroom control permission scopes in google apps scripts for student access 如何在谷歌脚本中格式化从扫描仪收到的数据? - How do I format data I have received from a scanner in google scripts?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM