Save files to Google Drive automatically from Gmail
I have been using Gmail since it’s inception when it was still an invite only email service and haven’t looked back. It’s flexibility and speed have made it my personal email account of choice and with Google steadily adding more services to Gmail and their other online collaboration tools it’s always getting better. So I was intrigued when I found out that Google were giving you a way to extend their Google Apps services further with Google App Script. Although it’s primarily aimed towards businesses that are leveraging Google Apps, you can use App Script to automate your own workflows to make your digital life that little bit easier.
For more information on App Script please visit the App Script Developer Site
In this post I will share a quick Google App Script that I wrote to save email bills sent as PDF’s automatically to my Google Drive, in the correct folder and then label the original email with a Gmail label. It’s pretty annoying having to go through your email and click save and then placing the file into the right folder each time, why not just automate it, so it’s in the right folder with the month-year of when it was received and synced to my laptop.
So let’s start by first creating our App Script Project, head over to script.google.com and change the project name to something descriptive, like Save PDF’s from Telstra. Following the Project name, copy and paste the following JavaScript code to the App Script IDE:
|
|
Continuing on, we now need to save and run the script’s Main function()
, when you run the script initially you will be presented with the following dialog box’s asking you to authorise the code to be run against your Google services.


If you allow the script to be run, you should see a new folder created in your Google Drive called Bills with the relevant bills saved and with the correct timestamp of the year-month they were received.
So the last thing you need to do is to add a trigger, the trigger is when you want the script to be run automatically without any user interaction.

Clicking the timepiece icon will present the following dialogue:

I run my script once a week, but you can run it however often you would like.
So there you have it, a script to save email attachments sent via Gmail to Google Drive automatically, hopefully you can use this snippet of code for your own workflows.