回复Gmail线索会向我发送电子邮件 [英] Replying to Gmail thread sends email to myself

查看:128
本文介绍了回复Gmail线索会向我发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档: 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(无法HTML,{
htmlBody:< b>一些HTML正文文本< / b>,
replyTo:theirEmailAddress,
});

但是,replyTo实际上只是指定了要发送的电子邮件的回复部分,我们收到。它与实际的字段aka收件人无关。



如果我做了 replyAll ,那么电子邮件的标题是:

  from:me@me.com 
to:them@them.com
抄送:me@me.com
code>

因此,我从自己那里收到了一堆电子邮件。我尝试将cc指定为none,但这并未改变 cc 字段。

  threads [0] .replyAll(只是想跟进,看看你是否收到我的最后一封电子邮件。,{
htmlBody:followUpText,
cc:null,
}) ;

如何追踪电子邮件并将其发送给最后一封电子邮件的原始收件人?

解决方案

已更新。
如果您已发起消息&没有收到回复,您可能需要使用 GmailApp.search() 在发送的项目中查找它。获得消息后,您可以使用 message.forward() 。请注意,您无法使用 message.forward()修改电子邮件的文本正文,但您可以设置 htmlBody 在选项对象中。

例如

  var unanswered = GmailApp.search('subject: 未回复in:sent'); 
var messages = unanswered [0] .getMessages();
var lastMsg = messages [messages.length - 1]; //获取线程中的最后一条消息,以防万一您发送了多个不同的提醒,其中包含不同的
//设置后续文本。
// +请注意,message.forward()不会将该线程附加到回复中,因此您必须自己执行此操作
var followupHTML ='< p>您的后续消息。< ; / p>< div class =gmail_quote>'+ lastMsg.getBody()+'< / div>';
lastMsg.forward(lastMsg.getTo(),{subject:lastMsg.getSubject(),htmlBody:< p>< b>转发< / b>< / p>+ followupHTML});

否则,对于存在于收件箱中的线程,可以使用如下所示的内容:
检查最近的&使用 message.forward()与上面一样,你是发件人,否则,只需回复。

  var firstThread = GmailApp.getInboxThreads(0,1)[0]; 
var messages = firstThread.getMessages();
var lastMsg = messages [messages.length - 1]; //获取线程中的最后一条消息
//设置后续文本。
// +请注意,message.reply()& message.forward()`不要将线程追加到回复中,所以你必须自己做这个 - 文本和文本。 HTML
var followupText =您的后续文本。@(lastMsg.getPlainBody())。replace(/ ^ / gm,>);
var followupHTML ='< p>您的后续消息。< / 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 =您的后续文本。;
var email_re = new RegExp(Session.getActiveUser()。getEmail(),i);
var mIdx = messages.length - 1; //最后一条消息索引
//向后走过线程& (email_re.test(messages [mIdx] .getFrom())){ - mIdx;}返回不是
的最新发件人的数组索引。 }
//现在,只需回复
messages [mIdx] .reply(followupText);

我在测试中绊倒的一件事是配额限制,因此在将邮件正文添加到您的邮件时需要谨慎响应文本。



希望这有助于。


Documentation: https://developers.google.com/apps-script/reference/gmail/gmail-message#replybody-options

When following up an email given there's no response after the initial email, reply() goes to myself, given I'm the one who sent the last email.

So for example, client A sends email to client B. Client A runs script below and reply goes to client A, but it should go to client B as it's only following up since there was no initial reply from B. At least that's how it goes in Gmail interface. I want to send a follow up.

I could run a separate sendmail, but that'll start a new thread unless you can specify the in-reply-to header or the user has responded to the existing thread, which they have not in my case.

Example code:

 message.reply("incapable of HTML", {
   htmlBody: "<b>some HTML body text</b>",
   replyTo: theirEmailAddress,
 });

However, replyTo actually just specifies the reply-to part of the email being sent, so the response that we receive. It has nothing to do with the actual to field aka recipient.

If I do replyAll, then the header for the email is:

from: me@me.com
to: them@them.com
cc: me@me.com

So from that, I get a bunch of emails from myself. I tried specifying cc as none but that didn't change the cc field.

threads[0].replyAll("Just wanted to follow up and see if you got my last email.", {
htmlBody: followUpText,
cc: null,
});

How do I follow up an email, and send it to the original recipient of the last email?

解决方案

Updated. If the you have initiate the message & not received a reply, you'll probably have to use GmailApp.search() to find it in the sent items. Once you have the message, you can then mimic the behaviour of the Gmail UI with message.forward(). Note that you can't modify the text body of the email with message.forward(), but you can set the htmlBody in the options object.

e.g.

  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});

Otherwise, for threads that are present in the inbox, you can use something like these: Check the most recent & use message.forward() as above is you are the sender, otherwise, just reply.

  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});
  }

Alternatively, traverse the thread & find the most recent sender that's not you & reply to that email.

  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);

One thing that i tripped over in my testing was the quota limit on the size of the reply email, so some circumspection is needed when including the message body in your response text.

Hope this helps.

这篇关于回复Gmail线索会向我发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆