google-apps-scriptgmail

Access delegated Gmail account to fetch labeled emails


So I've been busy compiling a code that is able to fetch all threads with a specific label 1 from Gmail Inbox, and parse certain elements of the messages into a sheet, and then remove label1 and add label2.

That works fabolously, but i tried this with my "personal" gmail account. I can't authorize the script to run on the delegated department's account.

Is there any workaround to this?

As far as i could find out, I can't really define the account in the code itself, and in the beginning of 2019 there was no possibility to do it.


Solution

  • What you need is to have a service account with domain-wide authority, as explained in the documentation, from that service account you can run your script. This has to be enabled by your admin, to do so they can use this tutorial

    Lastly, since you mentioned you're using Apps Script, this tutorial will show you how to use the service account through Apps Script.