0
votes

I'm trying to create a Google Apps Script to delete some email in bulk. The code for this doesn't really matter though as the GMailApp object isn't defined. I create a new project, add the following code:

function main() {
  var threads = GMailApp.search('.....');
}

and I just get an error 'ReferenceError: GMailApp is not defined'. Do I have to enable the GMailApp? I thought the point of the app services was that they didn't need an API to be enabled, and that they can just be linked and used.

Any help appreciated,

Thanks

4

4 Answers

2
votes

It's easy to avoid typos by getting used to using the "Control-Spacebar" short cut.

When you are in the Apps Script IDE holding control and spacebar at the same time will give you a popup of all the classes and then you just select the one you want.

1
votes

From menu select "Resources" -- "Advanced Google Services" and turn "Gmail API" on.

enter image description here

Pay attention to write in code GmailApp, not GMailApp.

0
votes

So in summary, the API object is GmailAPP, not GMailApp. The autocomplete with ctrl+space should help with problems like these however at some point I had it autocompleting my code so it must have got confused down the line. Thank you for your answers.

0
votes

2021 Update for the Gmail API (not GmailApp)

If you're in the 2021 and later IDE, it's here:

enter image description here

Also, note that Gmail is different from GmailApp. In my experience Gmail is more customizable, because you're getting exposed to the Gmail API whereas GmailApp is a less-robust collection of methods, but it's simpler to use.