Quickstart: Automation

Stay organized with collections Save and categorize content based on your preferences.

Build and run a simple automation that creates a Google Doc and emails you a link to it.

Before you begin

To use this sample, you need the following prerequisites:

  • A Google Account (Google Workspace accounts might require administrator approval)
  • A web browser with access to the internet

Set it up

To build the automation, take the following steps:

  1. Sign in to your Google Account.
  2. To open the script editor, go to script.google.com. If this is the first time you've been to script.google.com, click View Dashboard.
  3. At the top left, click New project.
  4. Delete any code in the script editor and paste in the code below.

     * Creates a Google Doc and sends an email to the current user with a link to the doc.
    function createAndSendDocument() {
      try {
        // Create a new Google Doc named 'Hello, world!'
        const doc = DocumentApp.create('Hello, world!');
        // Access the body of the document, then add a paragraph.
        doc.getBody().appendParagraph('This document was created by Google Apps Script.');
        // Get the URL of the document.
        const url = doc.getUrl();
        // Get the email address of the active user - that's you.
        const email = Session.getActiveUser().getEmail();
        // Get the name of the document to use as an email subject line.
        const subject = doc.getName();
        // Append a new string to the "url" variable to use as an email body.
        const body = 'Link to your doc: ' + url;
        // Send yourself an email with a link to the document.
        GmailApp.sendEmail(email, subject, body);
      } catch (err) {
        // TODO (developer) - Handle exception
        Logger.log('Failed with error %s', err.message);
  5. At the top, click Save .

  6. At the top left, click Untitled project.

  7. Enter a name for your script and click Rename.

Try it out

To run the script, take the following steps:

  1. At the top of the editor, click Run.
  2. In the first dialog box that appears, click Review permissions.
  3. When prompted, authorize the script. If the OAuth consent screen displays the warning, This app isn't verified, continue by selecting Advanced > Go to {Project Name} (unsafe).

  4. When the script execution completes, check your Gmail inbox for the new email.

  5. Open the email and click the link to open the Google Doc you created.

To continue learning about Apps Script, take a look at the following resources: