Created
February 19, 2014 07:53
-
-
Save ogawa/9087781 to your computer and use it in GitHub Desktop.
Google Appsでフォームでの投稿をメールで通知するスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// email address(es) for notification | |
var NOTIFY_RECIPIENT = '[email protected]'; | |
var ADMIN_RECIPIENT = NOTIFY_RECIPIENT; | |
function sendEmailOnFormSubmit(e) { | |
var body = ''; | |
var footer = ''; | |
try { | |
var range = SpreadsheetApp.getActiveSheet().getDataRange(); | |
var values = e.values; | |
for (var i = 0; i < values.length; i++) { | |
var key = range.getCell(1, i + 1).getValue(); | |
var value = values[i]; | |
body += '[' + key + ']\n' + value + '\n\n'; | |
} | |
body += footer; | |
// send a notification mail | |
var subject = SpreadsheetApp.getActiveSpreadsheet().getName(); | |
var options = {}; | |
MailApp.sendEmail(NOTIFY_RECIPIENT, subject, body, options); | |
} catch (err) { | |
var subject = 'Error: ' + SpreadsheetApp.getActiveSpreadsheet().getName(); | |
MailApp.sendEmail(ADMIN_RECIPIENT, subject, err.message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment