Saves the attachments from senders you nominate into a Google Drive folder, and labels the mail so nothing is filed twice.

UsesGmailGoogle 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 labeled '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.

Run every hour.Run every hour.
Set senders to blank.Set senders to blank.
Set driveFolderUrl to blank.Set driveFolderUrl to blank.
Set filedLabel to “Filed to Drive”.Set filedLabel to “Filed to Drive”.
Set filedLines to an empty list.Set filedLines to an empty list.
Split senders by “,” and save it as senderList.Split senders by “,” and save it as senderList.
For each sender in senderList:For each sender in senderList:
Trim sender and save it as address.Trim sender and save it as address.
If address is emptyIf address is empty
Yes
Skip to the next item.Skip to the next item.
No
No steps
Set latestMatch to nothing.Set latestMatch to nothing.
If a step below fails, save the error as searchErrorIf a step below fails, save the error as searchError
Try
GmailGmailFind email matching 'from:address has:attachment'. Save it as latestMatch.Find email matching 'from:address has:attachment'. Save it as latestMatch.
On error
Show in the output: Could not search mail from address - searchError as text.Show in the output: Could not search mail from address - searchError as text.
Skip to the next item.Skip to the next item.
Set latestMessageId to blank.Set latestMessageId to blank.
If a step below fails, save the error as latestIdErrorIf a step below fails, save the error as latestIdError
Try
Trim latestMatch.email.id and save it as latestMessageId.Trim latestMatch.email.id and save it as latestMessageId.
On error
Change latestMessageId to blank.Change latestMessageId to blank.
If latestMessageId is emptyIf latestMessageId is empty
Yes
Show in the output: No mail with attachments from address to file.Show in the output: No mail with attachments from address to file.
Skip to the next item.Skip to the next item.
No
No steps
Set filedMatch to nothing.Set filedMatch to nothing.
If a step below fails, save the error as filedSearchErrorIf a step below fails, save the error as filedSearchError
Try
GmailGmailFind email matching 'from:address has:attachment label:“@filedLabel”'. Save it as filedMatch.Find email matching 'from:address has:attachment label:“@filedLabel”'. Save it as filedMatch.
On error
Show in the output: Could not check what has already been filed for address - filedSearchError as text.Show in the output: Could not check what has already been filed for address - filedSearchError as text.
Skip to the next item.Skip to the next item.
Set filedMessageId to blank.Set filedMessageId to blank.
If a step below fails, save the error as filedIdErrorIf a step below fails, save the error as filedIdError
Try
Trim filedMatch.email.id and save it as filedMessageId.Trim filedMatch.email.id and save it as filedMessageId.
On error
Change filedMessageId to blank.Change filedMessageId to blank.
If latestMessageId is filedMessageIdIf latestMessageId is filedMessageId
Yes
Show in the output: The latest attachments from address are already in Drive.Show in the output: The latest attachments from address are already in Drive.
Skip to the next item.Skip to the next item.
No
No steps
Set downloaded to nothing.Set downloaded to nothing.
If a step below fails, save the error as downloadErrorIf a step below fails, save the error as downloadError
Try
GmailGmailDownload the attachments on email latestMessageId. Save it as downloaded.Download the attachments on email latestMessageId. Save it as downloaded.
On error
Show in the output: Could not download the attachments from address - downloadError as text.Show in the output: Could not download the attachments from address - downloadError as text.
Skip to the next item.Skip to the next item.
Set savedFromSender to 0.Set savedFromSender to 0.
For each attachment in downloaded.documents:For each attachment in downloaded.documents:
Set attachmentRef to blank.Set attachmentRef to blank.
If a step below fails, save the error as referenceErrorIf a step below fails, save the error as referenceError
Try
Trim attachment.document_ref and save it as attachmentRef.Trim attachment.document_ref and save it as attachmentRef.
On error
Change attachmentRef to blank.Change attachmentRef to blank.
If attachmentRef is emptyIf attachmentRef is empty
Yes
Show in the output: Skipped an attachment from address 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.
Skip to the next item.Skip to the next item.
No
No steps
Set attachmentName to “attachment”.Set attachmentName to “attachment”.
If a step below fails, save the error as nameErrorIf a step below fails, save the error as nameError
Try
Trim attachment.filename and save it as attachmentName.Trim attachment.filename and save it as attachmentName.
On error
Change attachmentName to “attachment”.Change attachmentName to “attachment”.
If attachmentName is emptyIf attachmentName is empty
Yes
Change attachmentName to “attachment”.Change attachmentName to “attachment”.
No
No steps
Set attachmentType to “application/octet-stream”.Set attachmentType to “application/octet-stream”.
If a step below fails, save the error as typeErrorIf a step below fails, save the error as typeError
Try
Trim attachment.content_type and save it as attachmentType.Trim attachment.content_type and save it as attachmentType.
On error
Change attachmentType to “application/octet-stream”.Change attachmentType to “application/octet-stream”.
If attachmentType is emptyIf attachmentType is empty
Yes
Change attachmentType to “application/octet-stream”.Change attachmentType to “application/octet-stream”.
No
No steps
Set saved to nothing.Set saved to nothing.
If a step below fails, save the error as uploadErrorIf a step below fails, save the error as uploadError
Try
Google DriveGoogle DriveUpload file attachmentRef. Save it as saved.Upload file attachmentRef. Save it as saved.
On error
Show in the output: Could not save attachmentName from address to Drive - uploadError as text.Show in the output: Could not save attachmentName from address to Drive - uploadError as text.
Skip to the next item.Skip to the next item.
Add 1 to savedFromSender.Add 1 to savedFromSender.
Set savedLink to blank.Set savedLink to blank.
If a step below fails, save the error as linkErrorIf a step below fails, save the error as linkError
Try
Trim saved.upload_link and save it as savedLink.Trim saved.upload_link and save it as savedLink.
On error
Change savedLink to blank.Change savedLink to blank.
Set filedLine to “@attachmentName from address”.Set filedLine to “@attachmentName from address”.
If savedLink isn't emptyIf savedLink isn't empty
Yes
Change filedLine to “@filedLine - savedLink”.Change filedLine to “@filedLine - savedLink”.
No
No steps
Add filedLine to the end of filedLines and save it as filedLines.Add filedLine to the end of filedLines and save it as filedLines.
If savedFromSender is greater than 0If savedFromSender is greater than 0
Yes
If a step below fails, save the error as labelErrorIf a step below fails, save the error as labelError
Try
GmailGmailAdd label filedLabel to email latestMessageId.Add label filedLabel to email latestMessageId.
On error
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.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.
No
Show in the output: No attachments from address were saved this time.Show in the output: No attachments from address were saved this time.
If filedLines is emptyIf filedLines is empty
Yes
Show in the output: “Nothing 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.”.
No
Show in the output: Filed the length of 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.