Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
googleフォームからカレンダーへ登録するスクリプト
function sendMailGoogleForm() {
// 件名、本文、フッター
var subject = "[イベント登録ありがとうございます。]";
var body
= "イベント登録ありがとうございます。\n\n"
+ "------------------------------------------------------------\n";
var footer
= "------------------------------------------------------------\n\n"
+ "";
// 入力カラム名の指定
var NAME_COL_NAME = 'お名前';
var GROUP_COL_NAME = '団体名';
var TITLE_COL_NAME = 'タイトル';
var MESSAGE_COL_NAME = '詳細';
var MAIL_COL_NAME = 'メールアドレス';
var START_TIME = "開始";
var END_TIME = "終了";
var LOC_COL_NAME="場所";
var groupName;
var title ;
var start ;
var end;
var message;
var loc;
// メール送信先
var admin = "admin@example.com"; // 管理者(必須)
var cc = ""; // Cc:
var bcc = admin; // Bcc:
var reply = admin; // Reply-To:
var to = ""; // To: (入力者のアドレスが自動で入ります)
//------------------------------------------------------------
// 設定エリアここまで
//------------------------------------------------------------
try{
// スプレッドシートの操作
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getLastRow();
var cols = sheet.getLastColumn();
var rg = sheet.getDataRange();
Logger.log("rows="+rows+" cols="+cols);
// メール件名・本文作成と送信先メールアドレス取得
for (var i = 1; i <= cols; i++ ) {
var col_name = rg.getCell(1, i).getValue(); // カラム名
var col_value = rg.getCell(rows, i).getValue(); // 入力値
body += ""+col_name+"\n";
body += col_value + "\n\n";
if ( col_name === TITLE_COL_NAME ) {
title = col_value;
}
if ( col_name === GROUP_COL_NAME ) {
groupName = col_value;
}
if ( col_name === START_TIME ) {
start = col_value;
}
if ( col_name === END_TIME ) {
end=col_value;
}
if ( col_name === NAME_COL_NAME ) {
body = col_value+"\n\n"+body;
}
if ( col_name === MAIL_COL_NAME ) {
to = col_value;
}
if ( col_name === MESSAGE_COL_NAME ) {
message = col_value;
}
if ( col_name === LOC_COL_NAME ) {
loc = col_value;
}
}
body += footer;
// 送信先オプション
var options = {};
if ( cc ) options.cc = cc;
if ( bcc ) options.bcc = bcc;
if ( reply ) options.replyTo = reply;
// メール送信
if ( to ) {
MailApp.sendEmail(to, subject, body, options);
}else{
MailApp.sendEmail(admin, "【失敗】Googleフォームにメールアドレスが指定されていません", body);
}
}catch(e){
MailApp.sendEmail(admin, "【失敗】Googleフォームからメール送信中にエラーが発生", e.message);
}
id="自分のカレンダーID";
nt = CalendarApp.getCalendarById(id)
nt.createEvent(title+":"+groupName, new Date(start), new Date(end),{description:groupName+":\n"+message,location:loc});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment