QUICK TIP - How to Save Emails to Google Drive as PDF Files
- 1. QUICK TIP - Most Useful .htaccess Tricks for WordPress
- 2. QUICK TIP - How to Join and Earn From Brave Ads
- 3. QUICK TIP - PHP Regex Cheat Sheet
- 4. QUICK TIP - Bypass Google Drive Download Limit and Fix “Sorry you can’t view or download this file” Error
Today, I needed to save some of my Gmail emails to Google Drive as PDF files. I looked around for a bit. I tried CloudHQ, but I didn’t want to pay. Next, I looked into exporting my Google Data into an MBOX type format. This seemed reasonable at first, but then I had to find a tool to import MBOX into. I chose Thunderbird, but then Thunderbird wanted me to pay. Next, I tried a couple of other Chrome Extensions. Neither of these worked well.
Finally, I determined to get the emails to be outputted in the format that I wanted without paying, it was probably best to write a Google App Script.
What’s a Google App Script?
Well, according to Google, “Apps Script is a scripting platform developed by Google for light-weight application development in the G Suite platform.” You can learn more here. If you have a Gmail account, it looks like you should be able to use it.
I started by assigning all of the emails in Gmail that I wanted to export a Label. For the purpose of this tutorial, I created the label “Export”
After I created the label “Export”, I next associated the label with the emails that I wanted to save as PDF.
After selecting the emails that I wanted to export. I logged into the Google App Scripts by typing this url, https://script.google.com/. Once in Google App Scripts, I created a new project entitled Save Gmail to Google Drive. I had to give Google App Scripts access to both my Gmail and Google Drive.
Now to format the date use the following bit of code
function getFormattedDate( date )
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
month = (month < 10 ? "0" : "") + month;
day = (day < 10 ? "0" : "") + day;
hour = (hour < 10 ? "0" : "") + hour;
min = (min < 10 ? "0" : "") + min;
sec = (sec < 10 ? "0" : "") + sec;
var str = date.getFullYear() + "-" + month + "-" + day + "_" + hour + ":" + min + " ";
Next, run the code in Google App Scripts by hitting the play button.
Execute Google App Script Project to save Gmails to Google Drive as PDF
Navigate to your Google Drive My Gmail Folder. Voila! You’ll see your pdfs. This code will also handle attachments, which include calendar event types. Ping me if you have any issues, and I can share the script with you.
Export Emails to Google Drive as PDF