Last active
December 5, 2022 19:09
-
-
Save aquaerius/cd9f1598bab4ba36231ecbcfe5ffebd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let counter = 0; | |
function myFunction() { | |
//Find emails from sender no-reply@harborfreight.com or noreply@harborfreight.com that contain receipts attached | |
let senders = ["noreply@harborfreight.com", "no-reply@harborfreight.com"] | |
// Save them to a folder in Drive | |
senders.forEach( | |
(sender) => { searchMail(sender); } | |
) | |
} | |
function addAttachmentsToFolder(message) { | |
let folder = DriveApp.getFolderById(<YOUR-DRIVE-FOLDER-ID>); | |
message.getAttachments().forEach( | |
(attachment) => { | |
counter++; | |
let date = message.getDate(); | |
//Logger.log(date); | |
let name = date.getFullYear() + "/" + | |
(date.getMonth() + 1).toString() + "/" + | |
date.getDate().toString() + " " + | |
date.getHours().toString() + ":" + | |
date.getMinutes().toString() + " Receipt"; | |
Logger.log(name); | |
let file = DriveApp.createFile(attachment.copyBlob()).setName(name) | |
folder.addFile(file); | |
} | |
); | |
Logger.log(counter); | |
} | |
function searchMail(sender) { | |
let threads = GmailApp.search('receipt has:attachment from:' + sender); | |
threads.forEach( | |
thread => { | |
let messages = thread.getMessages(); | |
messages.forEach( | |
(message) => { | |
addAttachmentsToFolder(message); | |
} | |
) | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Google Apps Script to extract all receipts from a sender (Harbor Freight Tools) and save them to a folder in Google Drive.