GmailApp and DocumentApp Now Available to all Google Apps Script Users

With Google Apps Script, you can access your Calendar and Contacts, create Google Sites, send email, and lots more. But two integrations were noticeably missing: the Google Docs word processor, and Gmail - Google today announced that "GmailApp and DocumentApp are available to all Apps Script users."GmailApp - read, label and send emailsYou've access to […]

With Google Apps Script, you can access your Calendar and Contacts, create Google Sites, send email, and lots more. But two integrations were noticeably missing: the Google Docs word processor, and Gmail - Google today announced that "GmailApp and DocumentApp are available to all Apps Script users."

  • GmailApp - read, label and send emails
    You've access to labels, threads, and messages, and you can do all the things you expect: change labels, add and remove stars, mark things as important or trash or spam. You can also use GmailApp.search() method to do any search you can do in Gmail itself.

    "To make sure your Gmail account remains private and secure, we are extra cautious about any script that uses GmailApp. Any time you change the code for a script that accesses Gmail, we'll require you to reauthorize the script to run. Keep that in mind when editing a script that runs on a trigger - if you don't reauthorize it, it'll fail the next time the trigger tries to run it," Google explained.

  • DocumentApp - create and edit Docs
    "You can create new documents or open existing ones by id. The id of a document is always in the URL you see when visiting it, and document ids are consistent between DocumentApp and the existing DocsList service, so you can use DocsList.find() to search for a document, and then get its id from File.getId()," Google stated.

    "Once you've a document, you can access all of its individual elements. You can do search and replace (great for mail merge!), change styles or text, add or remove tables and lists, and much more. And when you're done, you can call Document.saveAndClose(), which makes sure all of your changes to the document get saved. If you don't call it, we'll do it for you at the end of the script, but it can be useful to call it yourself if you'd like to do something with the document after making your edits," Google said.

    More Info: GmailApp | DocumentApp

    [Source: Apps Developer Blog]