/**
* 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
console.log('Failed with error %s', err.message);
}
}
点击“保存”图标 。
点击未命名的项目。
输入脚本的名称,然后点击重命名。
运行脚本
如需运行此脚本,请按以下步骤操作:
点击运行。
根据提示为脚本授权。
如果 OAuth 权限请求页面显示警告 This app is not verify,请依次选择 Advanced>Go to {Project Name} (unsafe)。