【问题标题】:Count number of email sent to a person计算发送给某人的电子邮件数量
【发布时间】:2016-07-06 13:08:37
【问题描述】:
我正在尝试获取某人收到电子邮件的次数,以便我可以跟踪潜在客户,例如
user@domain.com was emailed 5 times
user2@domain.com was emailed 3 times
通过阅读文档我无法弄清楚这一点
这可能吗?
编辑:
function myFunction(e) {
e = "someemail@gmail.com";
var threads = GmailApp.search("to:" + e + "");
var count = 0;
for (var i = 0; i < threads.length; i++) {
count++;
}
Logger.log(count) //1
}
这给了我线程但没有消息数
【问题讨论】:
标签:
google-apps-script
gmail
【解决方案1】:
我认为您使用 search() 查找发送的项目是正确的。这是我用来扫描收件箱中所有未读电子邮件以及处理该电子邮件的 sn-p。你会想要类似的东西:
var totalThreads = GmailApp.getInboxThreads().length
// Read in READ_AT_ONCE pages of email at a time
for (var pageindex = 0; pageindex < totalThreads; pageindex += READ_AT_ONCE) {
var threads = GmailApp.getInboxThreads(pageindex, READ_AT_ONCE)
var msgs = GmailApp.getMessagesForThreads(threads)
var numThreads = threads.length
// Read in all the threads in the batch
for (var threadIndex = 0; threadIndex < numThreads; threadIndex++) {
var numMsgs = msgs[threadIndex].length
// Process each msg in the thread
for (var msgIndex = 0; msgIndex < numMsgs; msgIndex++) {
var msg = msgs[threadIndex][msgIndex]
if (!msg.isUnread() || msg.isInTrash()) {
continue
}
Email_.processMsg(msg)
} // for each msg
} // for each thread
} // for each batch