迭代gmail线程并使用addlabel添加标签

时间:2016-02-07 09:54:01

标签: javascript multithreading gmail-api

我希望每天两次运行这个独立代码,但是无法解决addLabel上的异常,这是"无法找到方法",有什么建议吗?我试图改变for循环以及为线程[i]分配一个var,但没有改变。

function salvaNote(){

var d = new Date();
d.setMonth(d.getMonth()-6);
var n = d.getFullYear() + "/" + addZero(d.getMonth()+1) + "/" + addZero(d.getDate()); 
var folderName = 'tavoloTecnico';
labelName = GmailApp.createLabel('tavoloTecnico');  
var query = 'in:anywhere from:mariano.casillo@mit.gov.it OR     from:donato.castigliego@mit.gov.it has:attachment subject:previsioni filename:xls '+ 'after:'+n;
var threads = GmailApp.search(query);
var quanteMail = threads.length;

    for ( var i = 0 ; i < quanteMail; i++) {
    threads[i].addLabel(labelName);
    var mesgs = threads[i].getMessages();
    for(var j in mesgs){

        var attachments = mesgs[j].getAttachments();
    for(var k in attachments){
        var attachment = attachments[k];
        var attachmentBlob = attachment.copyBlob();
        var file = DriveApp.createFile(attachmentBlob);
        DriveApp.getFoldersByName(folderName).next().addFile(file);
    }
    }
}
}

0 个答案:

没有答案