I created an script that can transfer my gmail attachment to gdrive, but I have to modify my script since it downloads all the gmail attachment even its already downloaded.
May I know what I need to modify on my script?
function saveGmailToGdrive(){
const folderId = "GDRIVE"
const searchItem = "label:MONEY"
const threads = GmailApp.search(searchItem,0,100)
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()
)
})
})
})
}
I hope someone can help me thank you!
In that case, how about storing the message IDs that the attachment files were downloaded? By this, after 2nd run of the script, the attachment files from only new messages can be downloaded by searching the message IDs.
Modified script:
Before you use this script, please create a new Spreadsheet and put the Spreadsheet ID to
spreadsheetId
.Reference: