2014-06-11 195 views
0

我很難搞清楚如何將標籤添加到我從腳本發送的電子郵件中,發送電子郵件的文檔沒有先進的參數,添加一個標籤:https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String,Object)Google Apps腳本:向發送的電子郵件添加標籤

這是我用.addLabel()而不是嘗試,但它不工作,有人想出了這個?

function myFunction() { 
    var test = "This is a email was sent from Google Apps Script."; 

    var subjectTitle = "This email was scripted via Google Apps Scripts"; 

    var email = Session.getActiveUser().getEmail(); 

    GmailApp.sendEmail(email, subjectTitle, test); 

    var labelthread = GmailApp.getInboxThreads(); 
    for (var j = 0; j < labelthread.length; j++) { 
    if (labelthread[j].getFirstMessageSubject() == subjectTitle) { 
     labelthread[j].addLabel("Scripted Email"); 
    } 
    } 
} 

回答

0

您可以在已發送郵件文件夾而不是收件箱中進行測試。

var thread = GmailApp.search("in:sent subject" + subjectTitle, 0, 1); 
var label = GmailApp.getUserLabelByName("Scripted Email"); 
thread[0].addLabel(label); 
+0

我試過了你的建議,但沒有奏效。它說addLabel不是一個公認的命令。 – user3334776

+0

查看更新的代碼。 –

+0

仍然遇到同樣的問題...你會認爲應該有一個內置的「sendEmail」函數標籤選項,但它只給出附件,密件,CC,from,htmlBody,inlineImages,name,noReply和replyTo ...像wtf – user3334776

相關問題