/** * Creates a Google Doc and sends an email to the current user with a link to the doc. */functioncreateAndSendDocument(){try{// Create a new Google Doc named 'Hello, world!'
constdoc=DocumentApp.create('Hello,world!');// Access the body of the document, then add a paragraph.doc.getBody().appendParagraph('ThisdocumentwascreatedbyGoogleAppsScript.');// Get the URL of the document.consturl=doc.getUrl();// Get the email address of the active user - that's you.constemail=Session.getActiveUser().getEmail();// Get the name of the document to use as an email subject line.constsubject=doc.getName();// Append a new string to the "url" variable to use as an email body.constbody='Linktoyourdoc: ' +url;// Send yourself an email with a link to the document.GmailApp.sendEmail(email,subject,body);}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failedwitherror%s',err.message);}}
Click Save .
Click Untitled project.
Enter a name for your script and click Rename.
Run the script
To run the script, take the following steps:
Click Run.
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).
When the script execution completes, check your Gmail inbox
for the email.
Open the email and click the link to open the document that you created.