Use*_*ser 5 javascript google-apps-script
文档:https : //developers.google.com/apps-script/reference/gmail/gmail-message#replybody-options
当跟进给出有初始电子邮件后没有反应电子邮件,reply()
去我自己,因为我是谁发送的最后一封电子邮件的一个。
因此,例如,客户端A向客户端B发送电子邮件。客户端A在下面运行脚本,然后答复客户端A,但是应该将其发送给客户端B,因为它是后续的,因为没有来自客户端B的初始答复。至少这样进入Gmail界面。我想跟进。
我可以运行一个单独的sendmail,但是它将启动一个新线程,除非您可以指定in-reply-to标头或用户已响应现有线程,但在我看来,它们没有。
示例代码:
message.reply("incapable of HTML", {
htmlBody: "<b>some HTML body text</b>",
replyTo: theirEmailAddress,
});
Run Code Online (Sandbox Code Playgroud)
但是,replyTo实际上只是指定要发送的电子邮件的回复部分,因此我们会收到响应。它与实际的to
字段又称为收件人无关。
如果我这样做replyAll
,则电子邮件的标题为:
from: me@me.com
to: them@them.com
cc: me@me.com
Run Code Online (Sandbox Code Playgroud)
因此,我从自己那里收到了一堆电子邮件。我尝试将cc指定为none,但这没有更改cc
字段。
threads[0].replyAll("Just wanted to follow up and see if you got my last email.", {
htmlBody: followUpText,
cc: null,
});
Run Code Online (Sandbox Code Playgroud)
如何跟进电子邮件,并将其发送给最后一封电子邮件的原始收件人?
更新。
如果您已发起消息但未收到回复,您可能需要GmailApp.search()
在已发送的项目中查找它。收到消息后,您可以使用 来模仿 Gmail UI 的行为message.forward()
。请注意,您无法使用 修改电子邮件的文本正文,但您可以在选项对象中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});
Run Code Online (Sandbox Code Playgroud)
否则,对于收件箱中存在的线程,您可以使用类似以下内容:检查最近的内容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});
}
Run Code Online (Sandbox Code Playgroud)
或者,遍历线程并找到不是您的最近发件人并回复该电子邮件。
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);
Run Code Online (Sandbox Code Playgroud)
我在测试中遇到的一件事是回复电子邮件大小的配额限制,因此在回复文本中包含邮件正文时需要谨慎。
希望这可以帮助。
归档时间: |
|
查看次数: |
1022 次 |
最近记录: |