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:
New editor
- Sign in to your Google Account.
- To open the script editor, go to
script.google.com
. If this is the first time you've been toscript.google.com
, click View Dashboard. - At the top left, click New project.
Delete any code in the script editor and paste in the code below.
At the top, click Save
.At the top left, click Untitled project.
Enter a name for your script and click Rename.
Legacy editor
- Sign in to your Google Account.
- To open the script editor, go to
script.google.com
. If this is the first time you've been toscript.google.com
, click View Dashboard. Delete any code in the script editor and paste in the code below.
Select the menu item File > Save. Name your new script and click OK.
Try it out
To run the script, take the following steps:
New editor
- At the top of the editor, click Run.
- In the first dialog box that appears, click Review permissions. In the second dialog box, review the permissions your script uses and click Allow.
- When the script execution completes, check your Gmail inbox for the new email.
- Open the email and click the link to open the Google Doc you created.
Legacy editor
- To execute the script, either click run ▶ or select the menu item Run > createAndSendDocument.
- A dialog box will appear and tell you that the script requires authorization. Click Continue. A second dialog box will then request authorization for specific Google services. Read the notice carefully, then click Allow.
- A yellow bar at the top of the script editor will indicate when the script is running. When the yellow bar disappears, the script has finished.
- Check your Gmail inbox for the new email, then click the link to open the Google Doc you created.
- Open your Google Drive. You'll see that both the script and the document are stored there.
Related resources
To continue learning about Apps Script, take a look at the following resources: