Google Apps脚本可以统计昨天收到的具有特定标签的电子邮件数量,然后每天将数据保存到电子表格 [英] Google Apps Script to count number of emails received yesterday, that has certain label, then save # daily to spreadsheet
问题描述
基本上标题是这样说的,但我想:
1)自动统计收到我的gmail帐户的电子邮件数量,该帐户上有一定的标签
2)每天计数一次,即使为零3)每天向Google Spreheets报告
4)因此,我可以创建一个月度报告,例如:
日期/#
日期/#
日期/#
。
。
。
10月合计/#
每日平均值/#
我确定这是对于脚本大师来说,使用Google脚本是一块蛋糕,但我不知道。请教我!
打开一个新的Untitled电子表格并转至工具 - >打开脚本编辑器并粘贴下面给出的代码。
函数CountEmail()
{
var label = GmailApp.getUserLabelByName(LabelName);
var labelname = label.getName();
var mails = label.getThreads();
var sheet = SpreadsheetApp.getActiveSpreadsheet()。getSheetByName(Sheet1);
var date = new Date();
sheet.appendRow([labelname,date,mails.length]);
}
要每天运行脚本,您需要在应用程序中设置项目触发器脚本。对于下面的步骤:
资源 - >当前项目的触发器 - >添加触发器 - >时间驱动 - >小时计时器 - >选择时间希望脚本运行。
只需使用Sum()函数就可以在电子表格中自动计算电子邮件总数和平均电子邮件数量。 p>
Basically what the title says, but I want to:
1) Automatically count the number of emails received to my gmail account, that has a certain label on it
2) Count once everyday, even if zero
3) And report daily to a Google Spreasheet
4) So I can make a monthly report like such:
Date / #
Date / #
Date / #
.
.
.
Total for October / #
Average per day / #
I'm sure this is piece of cake using Google Script for script gurus, but I have no clue. Please teach me!
Open a new Untitled spreadsheet and go to Tools -> open Script editor and paste the code given below.
function CountEmail()
{
var label = GmailApp.getUserLabelByName("LabelName");
var labelname = label.getName();
var mails = label.getThreads();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var date = new Date();
sheet.appendRow([labelname,date,mails.length]);
}
To run the script daily you will need to set a project trigger in the app script.For that follow the steps given below:
Resources -> Current Project's Trigger -> Add trigger -> Time driven -> Hour timer -> select the time when you want the script to run.
The total number of emails and the average emails/day can be calculated in the spreadsheet itself by just using the Sum() function.
这篇关于Google Apps脚本可以统计昨天收到的具有特定标签的电子邮件数量,然后每天将数据保存到电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!