[英]How to send a HTML email with attachment using MailApp in Google Apps Script?
[英]MailApp AppScript: How to send an email to a thread using MailApp?
我正在使用Appscript的 mailApp class 发送每日电子邮件,如下所示:
MailApp.sendEmail({to: emails[0],subject:subjectLine,htmlBody: htmlContent,cc: emails.slice(1,emails.length).join(",")});
我观察到,对于subjectline = "TestEmail"
如果多次发送它会被发送到一个新线程:
我真正想要的是不是 MailApp 创建一个新线程,如果主题行相同,它必须将其发送到旧线程。 例如: subjectline = "TestEmail"
那么这个主题内的所有邮件都应该属于同一个而不是分散的,如上所示。 并且仅当主题行更改时,它们才应落入新的 email 线程中。
有没有人遇到过同样的问题? 有谁知道同样的解决方法? 如果您有相同的解决方案,请告诉我。
提前致谢。
解决方法:
您可以在使用 Gmail 服务发送电子邮件时防止创建新线程
你需要做什么:
示例代码:
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()可让您搜索 Gmail 中的特定查询。 这将返回一个GmailThread[]类型,它是与此查询匹配的 Gmail 线程数组
GmailThread 中还有其他回复选项。 有关更多信息,您可以访问此链接: https://developers.google.com/apps-script/reference/gmail/gmail-thread
这样,您可以决定是否需要在 Gmail 中创建新线程或使用现有线程回复。
Output:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.