我试图在电子邮件上添加两个不同的标签。如果电子邮件包含"生产"或"许可证"它应该发送一封电子邮件并用" SentLabel2"。
标记如果邮件不包含"生产"或"许可证"它应该用另一个标签" NotSentLabel2"标记它。
问题: 它使用" NotSentLabel2"标记所有电子邮件。
var sub = message.getSubject();
var res = sub.match(/Production/g);
var res2 = sub.match(/License/g);
if (labels == undefined){
if (res == "Production"){
GmailApp.sendEmail(from, "test", "ok sounds good :)");
threads[i].addLabel(SentLabel2);
}
if (res2 == "License"){
GmailApp.sendEmail(from, "test", "ok sounds good :)");
threads[i].addLabel(SentLabel2);
}
if (res || res2 != "Production" || "License"){
threads[i].addLabel(NotSentLabel2);
}
答案 0 :(得分:0)
目前您的最后一个陈述始终为真,因为"License"
是真值。你会想要像
if(res !== "Production" && res2 !== "License") {...
但是当您使用正则表达式时,为什么不同时使用测试和测试
var sub = "Production";
if (/(Production)|(License)/g.test(sub)) {
console.log("matched")
} else {
console.log("didn't match anything")
}