google-apps-script - 是否有逆时针计算未读电子邮件的代码?
问题描述
我正在构建一个附加组件,它可以自动回复第一次向用户发送电子邮件的人,其中包含预设消息和收件箱中当前未读电子邮件的数量。
我打算使用电子表格作为数据库,如何创建一个代码来为每个人反向计算未读电子邮件?
解决方案
只需获取所有未读消息并按日期排序
function getUnreadMessages() {
var oA=['Date','From','Id','PlainBody'];
const threads=GmailApp.getInboxThreads();
threads.forEach(function(t,i){
let messages=threads[i].getMessages()
messages.forEach(function(m,j){
if(m.isUnread()) {
oA.push([m.getDate(),m.getFrom(),m.getId(),m.getPlainBody()]);
}
});
});
const ss=SpreadsheetApp.getActive();
const sh=ss.getSheetByName('UnReadMessages');
sh.clearContents()'
sh.getRange(1,1,oA.length,oA[0].length).setValues(oA).sort({column:1,ascending:false});
}
推荐阅读
- flutter - StreamBuilder 在颤动中列出条件后,帖子的顺序不起作用
- heroku - 从 Gitlab 部署的 Net Core Wep App 上的 Heroku 错误 R10(启动超时)
- mysql - 在 mysql 中不允许使用 FETCH 子句。改用什么替代方法
- python - django密码验证是否应该不起作用
- python - 更 Pythonic 的方式来做到这一点?
- jsp - 基于 tomcat 表单的身份验证出现错误 408
- terraform - 如何从状态文件中的主要版本降级 Terraform
- c# - 为什么有些无人机不动?
- jboss - Wildfly 堆栈跟踪日志记录格式预先添加战争名称
- report - 行号 RDLC 报告