/**
* 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 同意畫面顯示「這個應用程式未驗證」警告,請依序選取「Advanced」>「Go to {Project Name} (unsafe)」。