Skip to content

Instantly share code, notes, and snippets.

@allen501pc
Created September 15, 2013 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allen501pc/6568884 to your computer and use it in GitHub Desktop.
Save allen501pc/6568884 to your computer and use it in GitHub Desktop.
新版的Google表單API範例:寄發Email提醒
/* Gogole Form 專用發送EMail程序 */
function sendMails(e) {
// 取得使用者送出的資料(陣列)
var currentItemResponses = e.response.getItemResponses();
// 注意,每一筆array entry用來表示每個表單的問題與答案。
// 在本範例中,第一個entry是姓名(index 0),第二個entry是EMail (index 1)。
// 我們使用getItem可以獲得提問的問題選項物件,getResponse則是取得該問題的輸入答案。
// 例如index 0的提問選項為「使用者姓名」,而輸入的答案為「Allen」。則可以用以下語法獲得所需資料。
// Logger.log("Question %s = %s", currentItemResponses[0].getItem().getTitle(), currentItemResponses[0].getResponse());
// 取得姓名輸入資料
var userName = currentItemResponses[0].getResponse();
// 取得EMail輸入資料
var userEMail = currentItemResponses[1].getResponse();
/* 設定寄件內容,Mail.App.sendEMail()這個函式,
第一個參數為「EMail位址」,第二個參數為「標題」,第三個參數為「內容」。
以這個範例而言,我設定標題為 "表單測試: 使用者名稱",內容為"姓名:xxx submitted by Allen"
*/
MailApp.sendEmail(userEMail, "表單測試:"+ userName,
"姓名:" + userName + " submitted by Allen.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment