[英]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.