Saves the attachments from senders you nominate into a Google Drive folder, and labels the mail so nothing is filed twice.
Uses
Gmail
Google Drive
File email attachments into Google Drive
Every hour, for each sender you nominate, the workflow finds their most recent email with attachments and saves every attachment into a Google Drive folder you choose. Invoices, signed contracts and statements stop sitting in the inbox and land in one folder, each keeping its own file type, so a PDF arrives as a PDF and a spreadsheet as a spreadsheet.
Once an email's attachments are saved, the email is labelled 'Filed to Drive' and later runs check for that label before downloading anything, so the same attachments are never filed twice. A sender whose search fails, an attachment that will not upload or a folder the account cannot write to is reported and skipped, and the other senders still go through. Every run ends with a list of what was filed and a link to each file.
It takes each sender's latest message rather than working through a backlog, so running hourly keeps pace with mail as it arrives. All you need is a Drive folder to file into.
senders to blank.Set senders to blank.driveFolderUrl to blank.Set driveFolderUrl to blank.filedLabel to Filed to Drive.Set filedLabel to Filed to Drive.filedLines to an empty list.Set filedLines to an empty list.senders by , and save it as senderList.Split senders by , and save it as senderList.sender in senderList:For each sender in senderList:sender and save it as address.Trim sender and save it as address.address is emptyIf address is emptylatestMatch to nothing.Set latestMatch to nothing.searchErrorIf a step below fails, save the error as searchErroraddress has:attachment'. Save it as latestMatch.Find email matching 'from:address has:attachment'. Save it as latestMatch.address - searchError as text.Show in the output: Could not search mail from address - searchError as text.latestMessageId to blank.Set latestMessageId to blank.latestIdErrorIf a step below fails, save the error as latestIdErrorlatestMatch.email.id and save it as latestMessageId.Trim latestMatch.email.id and save it as latestMessageId.latestMessageId to blank.Change latestMessageId to blank.latestMessageId is emptyIf latestMessageId is emptyaddress to file.Show in the output: No mail with attachments from address to file.filedMatch to nothing.Set filedMatch to nothing.filedSearchErrorIf a step below fails, save the error as filedSearchErroraddress has:attachment label:@filedLabel'. Save it as filedMatch.Find email matching 'from:address has:attachment label:@filedLabel'. Save it as filedMatch.address - filedSearchError as text.Show in the output: Could not check what has already been filed for address - filedSearchError as text.filedMessageId to blank.Set filedMessageId to blank.filedIdErrorIf a step below fails, save the error as filedIdErrorfiledMatch.email.id and save it as filedMessageId.Trim filedMatch.email.id and save it as filedMessageId.filedMessageId to blank.Change filedMessageId to blank.latestMessageId is filedMessageIdIf latestMessageId is filedMessageIdaddress are already in Drive.Show in the output: The latest attachments from address are already in Drive.downloaded to nothing.Set downloaded to nothing.downloadErrorIf a step below fails, save the error as downloadErrorlatestMessageId. Save it as downloaded.Download the attachments on email latestMessageId. Save it as downloaded.address - downloadError as text.Show in the output: Could not download the attachments from address - downloadError as text.savedFromSender to 0.Set savedFromSender to 0.attachment in downloaded.documents:For each attachment in downloaded.documents:attachmentRef to blank.Set attachmentRef to blank.referenceErrorIf a step below fails, save the error as referenceErrorattachment.document_ref and save it as attachmentRef.Trim attachment.document_ref and save it as attachmentRef.attachmentRef to blank.Change attachmentRef to blank.attachmentRef is emptyIf attachmentRef is emptyaddress because it was not stored and cannot be uploaded.Show in the output: Skipped an attachment from address because it was not stored and cannot be uploaded.attachmentName to attachment.Set attachmentName to attachment.nameErrorIf a step below fails, save the error as nameErrorattachment.filename and save it as attachmentName.Trim attachment.filename and save it as attachmentName.attachmentName to attachment.Change attachmentName to attachment.attachmentName is emptyIf attachmentName is emptyattachmentName to attachment.Change attachmentName to attachment.attachmentType to application/octet-stream.Set attachmentType to application/octet-stream.typeErrorIf a step below fails, save the error as typeErrorattachment.content_type and save it as attachmentType.Trim attachment.content_type and save it as attachmentType.attachmentType to application/octet-stream.Change attachmentType to application/octet-stream.attachmentType is emptyIf attachmentType is emptyattachmentType to application/octet-stream.Change attachmentType to application/octet-stream.saved to nothing.Set saved to nothing.uploadErrorIf a step below fails, save the error as uploadErrorattachmentRef. Save it as saved.Upload file attachmentRef. Save it as saved.attachmentName from address to Drive - uploadError as text.Show in the output: Could not save attachmentName from address to Drive - uploadError as text.savedFromSender.Add 1 to savedFromSender.savedLink to blank.Set savedLink to blank.linkErrorIf a step below fails, save the error as linkErrorsaved.upload_link and save it as savedLink.Trim saved.upload_link and save it as savedLink.savedLink to blank.Change savedLink to blank.filedLine to attachmentName from address.Set filedLine to attachmentName from address.savedLink isn't emptyIf savedLink isn't emptyfiledLine to filedLine - savedLink.Change filedLine to filedLine - savedLink.filedLine to the end of filedLines and save it as filedLines.Add filedLine to the end of filedLines and save it as filedLines.savedFromSender is greater than 0If savedFromSender is greater than 0labelErrorIf a step below fails, save the error as labelErrorfiledLabel to email latestMessageId.Add label filedLabel to email latestMessageId.address but could not label the email, so they may be filed again on the next run.Show in the output: Filed the attachments from address but could not label the email, so they may be filed again on the next run.address were saved this time.Show in the output: No attachments from address were saved this time.filedLines is emptyIf filedLines is emptyNothing new to file - the latest attachments from every sender are already in Drive..Show in the output: Nothing new to file - the latest attachments from every sender are already in Drive..filedLines as text attachment(s) into Drive:Show in the output: Filed the length of filedLines as text attachment(s) into Drive:
filedLines joined by a new line.