【发布时间】:2020-12-10 10:37:06
【问题描述】:
下面的应用脚本获取第一个 Gmail 收件箱线程的第一封邮件,并根据正则表达式检查“发件人:”标头。
根据结果,我们想使用addLabel() 设置Gmail 标签。
它执行提取和测试正常,但尝试设置标签时失败 - Cannot find method addLabel(string). (line 15, file "Code")
function myFunction() {
// Get first thread in Inbox.
var thread = GmailApp.getInboxThreads(0,1)[0];
// Get the first message in the thread.
var message = thread.getMessages()[0];
// Get a message header
var headerstring = message.getHeader("From");
// Check header for "rob" test string, apply label
if ( headerstring.match(/rob/g) ) {
thread.addLabel("MyLabel");
Logger.log("Matched rob");
} else {
thread.addLabel("AnotherLabel"); // failing, not class scope?
Logger.log("No match");
}
}
感觉addLabel 在if 子句中的存在已经剥夺了它的GmailApp 应用程序,因为我有addLabel 在一个之外运行- 对吗?这是我的第一个脚本。
我该如何克服这个问题?
【问题讨论】:
-
如错误状态,没有方法
addLabel(string)