- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
文档:https://developers.google.com/apps-script/reference/gmail/gmail-message#replybody-options
当跟进一封电子邮件时,假设在第一封电子邮件后没有回复,reply()
会转到我自己,因为我是最后一封电子邮件的发送者。
因此,例如,客户端 A 向客户端 B 发送电子邮件。客户端 A 运行下面的脚本并将回复发送给客户端 A,但它应该发送给客户端 B,因为它只是跟进,因为没有来自 B 的初始回复。至少Gmail 界面就是这样。我想发送一份跟进。
我可以运行一个单独的 sendmail,但除非你可以,否则这将启动一个新线程 specify the in-reply-to header或者用户已经回复了现有的线程,而在我的情况下他们没有。
示例代码:
message.reply("incapable of HTML", {
htmlBody: "<b>some HTML body text</b>",
replyTo: theirEmailAddress,
});
然而,replyTo 实际上只是指定了正在发送的电子邮件的回复部分,即我们收到的回复。它与实际的 to
字段(即收件人)无关。
如果我执行replyAll
,那么电子邮件的标题是:
from: me@me.com
to: them@them.com
cc: me@me.com
因此,我收到了一堆来 self 自己的电子邮件。我尝试将 cc 指定为 none 但这并没有改变 cc
字段。
threads[0].replyAll("Just wanted to follow up and see if you got my last email.", {
htmlBody: followUpText,
cc: null,
});
如何跟进电子邮件,并将其发送给上一封电子邮件的原始收件人?
最佳答案
已更新。如果您已发起消息但未收到回复,您可能必须使用 GmailApp.search()
在已发送的项目中找到它。收到邮件后,您可以使用 message.forward()
模仿 Gmail 用户界面的行为。 .请注意,您不能使用 message.forward()
修改电子邮件的正文,但您可以在选项对象中设置 htmlBody
。
例如
var unanswered = GmailApp.search('subject:"unanswered" in:sent');
var messages = unanswered[0].getMessages();
var lastMsg = messages[messages.length - 1]; // get the last message in the thread, just in case you have sent multiple reminders with different conent
// set your followup text.
// + Note that message.forward() doesn't append the thread to the reply, so you'll have to do this yourself
var followupHTML = '<p>Your followup message.</p><div class="gmail_quote">' + lastMsg.getBody() + '</div>';
lastMsg.forward(lastMsg.getTo(), {subject: lastMsg.getSubject(), htmlBody: "<p><b>forwarded</b></p>" + followupHTML});
否则,对于收件箱中存在的主题,您可以使用如下内容:检查最近的 & 使用 message.forward()
如上是你是发件人,否则,只是回复。
var firstThread = GmailApp.getInboxThreads(0,1)[0];
var messages = firstThread.getMessages();
var lastMsg = messages[messages.length - 1]; // get the last message in the thread
// set your followup text.
// + Note that message.reply() & message.forward()` don't append the thread to the reply, so you'll have to do this yourself -- both text & HTML
var followupText = "Your followup text.\n" + (lastMsg.getPlainBody()).replace(/^/gm, "> ");
var followupHTML = '<p>Your followup message.</p><div class="gmail_quote">' + (lastMsg.getBody()) + '</div>'
var email_re = new RegExp(Session.getActiveUser().getEmail(), "i");
if(email_re.test(lastMsg.getFrom())){
lastMsg.forward(lastMsg.getTo(), {lastMsg.getSubject(), htmlBody: followupHTML});
}
else{
lastMsg.reply(followupText, {htmlBody: followupHTML});
}
或者,遍历线程并找到不是您的最近发件人并回复该电子邮件。
var firstThread = GmailApp.getInboxThreads(0,1)[0];
var messages = firstThread.getMessages();
var followupText = "Your followup text.";
var email_re = new RegExp(Session.getActiveUser().getEmail(), "i");
var mIdx = messages.length - 1; // last message index
// walk backward through the thread & return the array index of the most recent sender that's not you
while(email_re.test(messages[mIdx].getFrom())){ --mIdx; }
// now, just reply
messages[mIdx].reply(followupText);
我在测试中绊倒的一件事是 quota limit关于回复电子邮件的大小,因此在回复文本中包含邮件正文时需要谨慎。
希望这对您有所帮助。
关于javascript - 回复 Gmail 线程会向我自己发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46896403/
我是一名优秀的程序员,十分优秀!