Automated script to extract spreadsheet files from email and save to Drive folder

I receive a weekly email every Tuesday containing two Excel file attachments that I need to process.

I want to create an automated solution that will:

  1. Search my inbox for emails from a specific sender with the subject line containing “Daily Sales Report for [date] and Daily Inventory Report for [date]”
  2. Extract both attached spreadsheet files from the email
  3. Create copies of these files in a designated Google Drive folder using the folder ID

I’m pretty new to Google Apps Script and haven’t been able to find good examples for this type of automation. The manual process of downloading and uploading these files each week is getting tedious. Has anyone built something similar or can point me in the right direction? Any help would be appreciated!

I’ve run similar automation for quarterly reports - attachment handling with Google Apps Script is definitely tricky. My biggest issue was Excel files getting corrupted during blob conversion. I fixed this by adding a file size check before processing each attachment. Saved me from timeouts on larger spreadsheets. Couple other things: Gmail search queries are case-sensitive, so test your search string first. I’d also create a backup subfolder in your Drive destination - files can get overwritten unexpectedly. Watch out for the 6-minute execution limit too. If you’re dealing with large Excel files, process them one at a time instead of both together.

Hey charlottew! I’ve done this exact thing before but had to use a different approach. Instead of searching by subject (which can be tricky with dates), I search by sender email and then check if attachments exist. One gotcha - make sure to handle file name conflicts when saving to drive or you’ll get duplicates. Also the Gmail API has daily limits so don’t run it too frequently for testing.

I built something similar for monthly reports. The key is using GmailApp.search() to filter emails by sender and subject text. For attachments, loop through each message’s attachments and use getBlob() to grab the file data. To save files to Drive, use DriveApp.getFolderById() then createFile() to dump them in your target folder. I ran into problems with date formats in subjects, so make sure your search handles variations. Add error handling for missing attachments or Drive access issues. Set up weekly time-based triggers to keep everything running smoothly.