gpt4 book ai didi

google-apps-script - 获取通过谷歌脚本发送的邮件的线程 ID

转载 作者:行者123 更新时间:2023-12-01 10:45:33 25 4
gpt4 key购买 nike

是否可以通过MailApp.sendEmail()获取邮件发送的线程id。我想在邮件发送后用标签标记它。

MailApp.sendEmail("samplemail@gmail.com","Sellers Required for pilot",msg_to_bd);
//get thread id for this mail, say thread 1
thread1.addLabel(labll);

最佳答案

首先,由于您要为刚刚发送的线程添加标签,因此您必须使用 GmailApp。 MailApp 只允许您发送邮件,不能与用户的收件箱交互。

如您所见,GmailApp.sendEmail() 不返回消息或线程 ID。在这种情况下,您可以搜索刚刚发送的线程,但您必须考虑何时向此人发送了多条消息。

只要您不很快发送重复的邮件,您就可以相信调用 GmailApp.search() 将按照与 Web UI 相同的顺序返回线程。因此,搜索“from:me to:customer123@domain.net”可能会返回许多线程,但第一个结果将是最近发送的消息的线程。

一个玩具示例,我们将邮件发送到名为 Recipients 的选项卡中列出的一堆地址:

var recipients = SpreadsheetApp.getActiveSpreadsheet()
.getSheetByName('Recipients')
.getDataRange()
.getValues();
recipients.shift(); // Only if the Recipients sheet contained a header you need to remove
var d = new Date();
var dateText = d.toLocaleString(); // Pretty-printed timestamp
var newLabel = GmailApp.createLabel(dateText); // Label corresponding to when we ran this
for (var i = 0; i < recipients.length; i++) {
GmailApp.sendEmail(recipients[i], 'This is a test', 'Of the emergency broadcast system');
var sentThreads = GmailApp.search('from:me to:' + recipients[i]);
var mostRecentThread = sentThreads[0];
mostRecentThread.addLabel(newLabel);
}

关于google-apps-script - 获取通过谷歌脚本发送的邮件的线程 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26757025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com