###### tags: `Google Apps Script` # Google App Script 01 寄送email ## Overview 總攬 舉個它強大的地方在它能超有效的調動google 的功能。在這邊直接看一個例子。 可以送出gmail的功能。 ```javascript /* Creates a Google Doc and sends an email to the current user with a link to the doc. */ function createAndSendDocument() { var doc = DocumentApp.create('Hello, world!'); //用DocumentApp.create()建立一個叫做Hello, world!的文件檔 doc.getBody().appendParagraph('This document was created by Google Apps Script.'); //用getBody()進入文件後,用appendParagraph新增我們想要的內容 var url = doc.getUrl(); //取得文件本身的網址 var email = Session.getActiveUser().getEmail(); //用函數去得你個人的email 地址,這邊惠要求你驗證是你,看到紅色警告, //不管。按進階選項照樣進入 var subject = doc.getName(); //用.getName取得文件你在上面建立時設定的名子 var body = 'Link to your doc: ' + url; //這個就不是很重要的東西,止是讓郵件中顯示出這個文件的網址而已 GmailApp.sendEmail(email, subject, body); //用GmailApp.sendEmail送出gmail,你知道一行就可以送出是多麼方便的嗎, //之前我自己用python用搞了老半天才能實現這個功能。 } ``` [官方範例](https://github.com/googleworkspace/apps-script-samples/blob/master/templates/standalone/helloWorld.gs)