[英]MailApp AppScript: How to send an email to a thread using MailApp?
I am using mailApp class of Appscript to send daily emails as shown below:我正在使用Appscript的 mailApp class 发送每日电子邮件,如下所示:
MailApp.sendEmail({to: emails[0],subject:subjectLine,htmlBody: htmlContent,cc: emails.slice(1,emails.length).join(",")});
What I observe is that for subjectline = "TestEmail"
if sent more than once it gets sent to a new thread:我观察到,对于subjectline = "TestEmail"
如果多次发送它会被发送到一个新线程:
What I actually want is to instead of MailApp creating a new thread, it must send it to the old thread if the subject line is the same.我真正想要的是不是 MailApp 创建一个新线程,如果主题行相同,它必须将其发送到旧线程。 Like for example: subjectline = "TestEmail"
then all the mails within this subject should fall under the same and not dispersed as shown above.例如: subjectline = "TestEmail"
那么这个主题内的所有邮件都应该属于同一个而不是分散的,如上所示。 And only when the subject line changes they should fall into a new email thread.并且仅当主题行更改时,它们才应落入新的 email 线程中。
Has anyone faced the same problem?有没有人遇到过同样的问题? Does anyone know any work around for the same?有谁知道同样的解决方法? Please let me know if you have a solution for the same.如果您有相同的解决方案,请告诉我。
Thanks in Advance.提前致谢。
Workaround:解决方法:
You can prevent creating a new thread when sending emails using Gmail Service您可以在使用 Gmail 服务发送电子邮件时防止创建新线程
What you need to do:你需要做什么:
Sample Code:示例代码:
var thread = GmailApp.search('in:anywhere subject:"Test_Email1" ')[0];
Logger.log(thread);
var invalidThread = GmailApp.search('in:anywhere subject:"Test_Email" ')[0];
Logger.log(invalidThread);
if (thread){
thread.reply("This is a reply");
}else{
Logger.log("Subject not found in mail");
}
var emailQuotaRemaining = MailApp.getRemainingDailyQuota();
Logger.log("Remaining email quota: " + emailQuotaRemaining);
GmailApp.search() lets you search for specific queries in Gmail. GmailApp.search()可让您搜索 Gmail 中的特定查询。 This will return a GmailThread[] type which is an array of Gmail threads matching this query这将返回一个GmailThread[]类型,它是与此查询匹配的 Gmail 线程数组
There are other reply options available in GmailThread. GmailThread 中还有其他回复选项。 For more information, you can visit this link: https://developers.google.com/apps-script/reference/gmail/gmail-thread有关更多信息,您可以访问此链接: https://developers.google.com/apps-script/reference/gmail/gmail-thread
By this, you may decide whether you need to create a new thread or reply with an existing thread in your Gmail.这样,您可以决定是否需要在 Gmail 中创建新线程或使用现有线程回复。
Output: Output:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.