如果声明或/不做什么?Gmail谷歌应用程序脚本
if statement or/not what to do? Gmail google apps script
我试图在电子邮件上添加两个不同的标签。如果电子邮件中包含"生产"或"许可证",则应发送一封电子邮件并标记为"SentRabel2"。
如果邮件中不包含"生产"或"许可证",则应使用另一个标签"NotSentRabel2"进行标记。
问题:它将所有电子邮件标记为"NotSentRabel2"
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);
}
当前您的最后一条语句始终为true,因为"License"
是一个truthy值。你想要这样的东西
if(res !== "Production" && res2 !== "License") {...
但是,既然您正在使用regex,为什么不同时使用测试和测试两者的呢
var sub = "Production";
if (/(Production)|(License)/g.test(sub)) {
console.log("matched")
} else {
console.log("didn't match anything")
}
相关文章:
- 谷歌地图固定位置覆盖
- 不显示带有本地json文件数据的谷歌地图脚本
- 谷歌脚本在第二次调用Gmail后返回null
- 我想构建一个代码,在谷歌应用程序脚本中检查我在Gmail中导入的邮件,我该如何找到这个功能
- 谷歌脚本 - 将 Gmail 附件添加到文档和云端硬盘中的处理
- 在谷歌应用程序脚本gui中显示gmail消息
- 如果声明或/不做什么?Gmail谷歌应用程序脚本
- 在gmail线程中从ZIP文件中提取CSV,并将数据写入谷歌表单
- 谷歌脚本的Gmail删除电子邮件与*仅*指定的标签
- 需要重定向到谷歌应用程序电子邮件登录页面,而不是在passportjs和nodejs正常gmail登录
- 动态设置谷歌脚本时间驱动的计时器和太多的计时器错误在gmail
- 绑定谷歌脚本gmail
- 获得未读计数在发送文件夹使用谷歌应用程序脚本- GMail
- 从gmail抓取html表格,并使用谷歌应用程序脚本放入谷歌表格
- 如何导入数据的gmail联系人,使用javascript谷歌联系人API,在更详细的格式
- 谷歌新的Gmail工具栏使用了什么风格
- 代码注入到Gmail通过谷歌Chrome扩展-如何确保我的脚本注入时,它已完成加载
- 附加文件从谷歌驱动器到gmail api撰写邮件
- 谷歌chrome扩展-我如何使用javascript添加一个x头字段到Gmail头
- Gmail getElementById('canvas_frame')保持返回null在谷歌Chrom