Save Gmail Attachments to Google Drive
Thanks to my Paper Backup I save all kinds of invoices and other documents I get by snail mail in my Google Drive. But of course there are also invoices that get delivered by email. Usually they come as a PDF attachment. Wouldn't it be nice to save those PDFs in Google drive as well?
Unfortunately Google Mail's filters do not allow to automate this. Luckily there's Google Apps Script.
I wrote a script to automatically save all attachments from mails within a certain Gmail label to Google Drive. Here's how you can use it, too:
- In Gmail create a new Label. eg.
Invoices. Feel free to create sub labels for more fine grained control.
- Create Filters to automatically sort your invoices into those labels
- I recommend to pick the “has attachment” option
- Be sure to use the “Star it” option - we use stars to track which mails have been processed already
- you probably also want to apply the filter to matching conversations
- Follow this link to see my script
- Select “Make a copy” from the “File” menu
- Give the needed permissions
- Adjust the top two variables
GMAIL_LABELis the label you created in Step 1
GDRIVE_FILEis the path and file name that will be used to save attachements (see below for the placeholders)
- Check “Resources - Current Project's trigger” an make sure the
mainmethod is called periodically (up to you how often).
After a while your attachments should start showing up in your Google Drive.
For configuring the location you can use the following placeholders in
| ||The original attachment name|
| ||The file extension of the original attachment|
| ||The domain part of the sender who sent the attachment|
| ||The sub label(s) under your configured label where the message was found|
| ||Year the message was received at|
| ||Month the message was received at|
| ||Day the message was received at|
| ||Hour the message was received at|
| ||Minute when the message was received at|
| ||Second when the message was received at|
| ||The message number in the thread, starting at 0|
| ||The attachment number in the thread, starting at 0|