Skip to content

Instantly share code, notes, and snippets.

@ogawa
Created February 19, 2014 07:53
Show Gist options
  • Save ogawa/9087781 to your computer and use it in GitHub Desktop.
Save ogawa/9087781 to your computer and use it in GitHub Desktop.
Google Appsでフォームでの投稿をメールで通知するスクリプト
// 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