google-apps-script - 谷歌应用程序脚本发送带有 n 个附件的邮件
问题描述
我似乎找不到任何可以完成我想要做的事情的东西,而且我对 JavaScript 的熟练程度不如我想的那样,所以请多多包涵……正如我在标题中提到的,我在谷歌应用程序脚本中写这个......
如果我有类似的代码:
function getMails() {
// get the first 5 threads
var threads = GmailApp.getInboxThreads(0, 5);
// get all the messages for the threads selected
var messages = GmailApp.getMessagesForThreads(threads);
// iterate through the threads
// ('messages' being the first message of the thread)
for (var i = 0; i < messages.length; i++) {
// then iterate through every message of the thread
var blobs = [];
for (var j = 0; j < messages[i].length; j++) {
// create a blob for every message
var blob = Utilities.newBlob(messages[i][j].getRawContent(),
'text/plain',
'message' + j + '.eml');
// push the blob into the array
blobs.push(blob);
}
// here's where I think I'm having trouble finding a solution
// and I do not want to zip all the blobbed messages into 1
MailApp.sendEmail(Session.getActiveUser().getEmail(),
"thread report: [" + messages[i][0].getSubject() + "]",
"attached message as text/plain", {
name: 'Automatic Emailer Script',
attachments: blobs
});
}
}
谁能给我一个指针,告诉我如何为每个线程的可变数量的消息完成这最后一步。
解决方案
在阅读了评论并重新尝试了代码(并修复了一些我错过的东西,因为我是即时编写的并且没有复制和粘贴我的工作/非工作代码)之后,我让它工作了!感谢大家对您的评论和见解的帮助。问题中的代码已被编辑并按预期工作。
推荐阅读
- python - 点子没更新?如何找到用户?
- python - 如何处理 Python Numpy 中的精度问题?
- javascript - 回调箭头函数不会从它的父函数继承“this”**这不是重复的**
- arrays - 尝试在 C 中创建打字效果
- html - 如何在带有方向列的 flex 中定位单个组件?
- r - 与 R 中的两个数据框相比,如何插入列(缺少日期)?
- javascript - 动态创建 React 应用程序安装在其上的元素
- c++ - 错误:C2061:语法错误:标识符'concurrent_vector<`template-type-parameter-1',`template-type-parameter-2'>'
- python-3.x - 列表作为字典值
- spring-data-jdbc - 自定义分页查询无法返回 Page
类型?