GAS(Google Apps Script)はなんでもできるよね!
本音で言えば、PHPが書ければ最高なんだけど。
簡単なことがJSだと手間取るんだよね・・・
ということで、メール一括送信スクリプトを作ったので、
ここ最近で書いた後で使えそうな稚拙なスニペットを覚書。
// ログインアカウントをチェック var auth_mail = "自分のgmailアドレス"; var User = Session.getActiveUser(); var mailaddress = User.getEmail(); if (mailaddress != auth_mail) { var kakunin = Browser.msgBox(auth_mail + "ではないアカウントから実行しますか?", Browser.Buttons.OK_CANCEL); if (kakunin != 'ok') return; }
// シートをテンプレートとして連想配列にする(「送信メール」というシートのA列=key, B列=valueとして) function getTemplateData () { var template = getSheetObj('送信メール').getDataRange().getValues(); var i = 0; var RETURN = {}; var Title = []; template.forEach (function (tmp) { var title = tmp[0]; var value = tmp[1]; if (title == '送信メールアドレス') { RETURN['from'] = value; } else if (title == '送信メール件名') { RETURN['subject'] = value; } else if (title == '送信メール本文') { RETURN['message'] = value; } else { RETURN[title] = value; } }); return(RETURN); }
// gmailからメール送信 //さっきのテンプレート連想配列とvalueには送り先情報を連想配列で、messageの中では___key___を value[key] と置換してます function sendMail (template, value) { var to = value['to']; var from = template['from']; var message = template['message']; var subject = template['subject']; var replyto = template['from']; // for (key in value) { var tmp = value[key]; var regexp = new RegExp("___" + key + "___", "g"); if ((tmp) && (key == 'date')) tmp = Utilities.formatDate( tmp, 'JST', 'yyyy年M月d日'); message = message.replace(regexp, tmp); } var regexp = new RegExp("___.*___", "g"); message = message.replace(regexp, ""); // if ((to) && (from) && (message) && (subject)) { var sousin = GmailApp.sendEmail(to, subject, message, { replyTo: replyto }); return(true); } }
0