需要使用app脚本从邮件中下载链接



我有一个问题的应用程序脚本,我正试图下载粘贴在内容驱动器的链接。

邮件示例如下

报告下载网址:xxxxxx.xlsx

上面的xxxxx.xlsx是我们下载文件的链接。我尝试下面的应用程序脚本代码。其他附件下载到驱动器,但上面的链接没有下载。请帮助。

function saveAttachmentInFolder(){
const folderId = 'Drive id';
const searchQuery = 'Report download URL';
const threads = GmailApp.search(searchQuery, 0,25);
threads.forEach(thread => {
const messages = thread.getMessages();
messages.forEach(message => {
const attachments = message.getAttachments({
includeInlineImages: false,
includeAttachments: true
});
attachments.forEach(attachment => {
Drive.Files.insert(
{
title: attachment.getName(),
mimeType: attachment.getContentType(),
parents: [{ id: folderId }]
},
attachment.copyBlob()
);
});
});
});
};

很明显,您无法在getAttachments中获得它,因为它不是附件

你可能需要刮掉邮件的内容。

/*
declare before the loop
const urls = [];
*/
const body = message.getBody();
//const body = message.PlainBody();
// you may need to adjust it in case there is any html code
const match = body.match(/Report download URL:.*(S+.xlsx)/);
if (match) { urls.push(match[1]); }

引用:

getBody ()

getPlainBody ()

最新更新