Created
April 17, 2024 03:55
-
-
Save ayumin/2fce979a327c0b35fa3972f8e5cfbaf3 to your computer and use it in GitHub Desktop.
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
function sendBySheet() { | |
/* | |
* SpreadSheetのmemberシートを取得 | |
*/ | |
const sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName('members'); | |
const result = sheet.getSheetValues(1, 1, 5000, 3); | |
let list = []; | |
// Emailリストを配列に格納 | |
for (let i = 1; i < 1000; i++) { | |
let email = result[0, i][0]; | |
let knickname = result[0, i][1]; | |
let status = result[0, i][2]; | |
if (email == "") { | |
break; | |
} | |
list.push({ "email": email, "knickname": knickname, "status": status }); | |
} | |
const subject_template = "さ党 - %knickname% さん 入党ありがとうございます"; | |
const body_template = "%knickname% さん\n \ | |
\n \ | |
さ党(さとうさおり後援会)への入党ありがとうございます\n \ | |
\n \ | |
公式X(旧Twitter)アカウント\n \ | |
さ党の公式X(旧Twitter)アカウントを開設しました。\n \ | |
さとうさおりの政治活動や、政治団体さ党に関するお問合せはこちらのアカウントのDMでも受け付けています。\n \ | |
X(旧Twitter)をお使いの方は、ぜひこちらのアカウントをフォローしてください。\n \ | |
https://x.com/satosaori_sato \n \ | |
\n \ | |
=====\n \ | |
さ党の運営に関するお問い合わせは、こちらのフォームからお願いします。\n \ | |
https://satosaori.doorkeeper.jp/contact/new \n \ | |
"; | |
const option = { name: 'さ党(さとうさおり後援会)' }; | |
for (i = 0; i < list.length; i++) { | |
let row = list[i]; | |
switch (row.status) { | |
case "sent": | |
sheet.getRange(i + 2, 1).setValue(row.email); | |
sheet.getRange(i + 2, 2).setValue(row.knickname); | |
sheet.getRange(i + 2, 3).setValue(row.status); | |
break; | |
case "pend": | |
sheet.getRange(i + 2, 1).setValue(row.email); | |
sheet.getRange(i + 2, 2).setValue(row.knickname); | |
try { | |
let subject = subject_template.replace(/%knickname%/, row.knickname); | |
let body = body_template.replace(/%knickname%/, row.knickname); | |
GmailApp.sendEmail(row.email, subject, body, option); | |
sheet.getRange(i + 2, 3).setValue("sent"); | |
sheet.getRange(i + 2, 4).setValue(new Date()); | |
console.log("[SENT]",row.email,"に送信完了"); | |
} catch (e) { | |
Logger.log(e); | |
sheet.getRange(i + 2, 3).setValue("error"); | |
} | |
break; | |
default: | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment