/** * 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("This document was created by Google Apps Script.");// 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=`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 exceptionconsole.log("Failed with error %s",err.message);}}
Klik Simpan.
Klik Project tanpa judul.
Masukkan nama untuk skrip Anda, lalu klik Ganti nama.
Jalankan skrip:
Untuk menjalankan skrip, lakukan hal berikut:
Klik Run.
Saat diminta, izinkan skrip.
<<../samples/_snippets/oauth.md>>
Setelah eksekusi skrip selesai, periksa email di
kotak masuk Gmail
Anda.
Buka email dan klik link untuk membuka dokumen yang Anda buat.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2026-03-17 UTC."],[],[]]