Consolidate emails (in Gmail) into a Google Docs document


Ever want to consolidate some emails into a google docs?
For my simple use case, somehow I didn't manage to find a free tool that does this.
Plus, I don't really want to expose my precious emails to random third party tools.

Turns out, it's pretty simple to use Google's AppScript to do this!
(Well, your mileage may vary depending on the complexity of the emails you want to consolidate)

Regardless, I will leave this boilerplate code here.
Just know that it's possible to do it for free :D

Getting Started Guide:

  1. 1. Make a copy of GmailConsolidator_Doc.

    https://docs.google.com/document/d/1yILhS1DgvXhytZvsKxsJvdoEnj9GszpsqzDtJAF35Fs/view


    This allows you to edit your own copy and later on, isolate the access to your own Gmail to your own script.

  2. 2. Now, open the copied document (on your gdrive now, not mine) and open Extensions > Apps script

    Take a look at the gmail_filter. This is exactly the same as your gmail filter bar.
    Customize this filter as necessary to only include emails that you want to consolidate in the google doc.
    You should test this on your own inbox first :)

    https://mail.google.com/mail/u/0/#search/is%3Aunread+newer_than%3A7d+category%3Aupdates



  3. 3. Change the Function dropdown to run "extractMessages", and click "Run"

    Now you have to grant the Apps script some permissions.
    Don't worry, you are granting permission to your own copy of the script (not mine!).
    (If you want to be very sure, rename your Apps script and you will see the name of your Apps script instead of "GmailConsolidator").

    Click "Review permissions".

    Sign in to your gmail.

    Click "Advanced".

    Then "Go to GmailConsolidator (unsafe)"

    Select all, then click "Continue".
Voila! The script should run and populate your Google Docs (the one that you copied)
Now, the content is probably very messy (take a look at this mail from TechInAsia)

So, you probably have to parse the msg body accordingly - hopefully your use case is not too complicated :p
Note: You might want to use msg.getBody() to parse HTML instead of plain text.

Cleaning Up Access:

  1. After you are done with your task,
    You can go to Google Account Permissions

    https://myaccount.google.com/permissions


    Find "GmailConsolidator",

    Then "Delete all connections you have with GmailConsolidator"
  2. Or maybe you want to make this a scheduled run - in that case, here's some Apps Script trigger documentation for you to read up on.
    Simple Triggers

I hope that saved you some pain and money.
Yes, you will still need to do most of the Apps Script coding, but I suppose this template can be a good starting point for you.

Here are further resources about Apps Script (or you can just ask chatGPT I guess):
Apps Script documentation

Cheers!