質問編集履歴

1

gas

2022/06/02 06:34

投稿

shirogohan
shirogohan

スコア14

test CHANGED
File without changes
test CHANGED
@@ -18,3 +18,62 @@
18
18
 
19
19
  ご教示お願いいたします。
20
20
 
21
+ ```
22
+ function SashikomiGmailSend() {
23
+
24
+ // Step1 : スプレッドシートの取得
25
+ const ss =
26
+ SpreadsheetApp.getActiveSpreadsheet();
27
+
28
+ const wsTemp = ss.getSheetByName("Templete");
29
+ const wsData = ss.getSheetByName("Data");
30
+
31
+ // Step2: データの取得
32
+ const lastRow = wsData.getLastRow();
33
+ const lastCol = wsData.getMaxColumns();
34
+ const datas = wsData.getRange (2,1, lastRow-1, lastCol).getValues();
35
+
36
+ // メールテンプレートの件名と本文を取得
37
+ const baseSubject = wsTemp.getRange("B2").getValue();
38
+ const baseBody = wsTemp.getRange("B3").getValue();
39
+
40
+ // 送信設定の取得
41
+ const folderID = wsTemp.getRange("B4").getValue();
42
+ const sendMode = wsTemp.getRange("B5").getValue();
43
+
44
+ // 配列番号1から繰り返し処理
45
+ for (let i = 1; i < datas.length; i++) {
46
+
47
+ // データを配列で取得
48
+ const data = datas[i];
49
+
50
+ // 配列番号を指定
51
+ const recipient = data[0];
52
+ const cc = data[1];
53
+ const bcc = data[2];
54
+ const company = data[3];
55
+ const request = data[4];
56
+ const date = data[5];
57
+ const options =
58
+ {
59
+ cc:cc,
60
+ bcc:bcc,
61
+ }
62
+
63
+ // Step3: 差し込み処理
64
+ const subject = baseSubject
65
+ .replace("${会社名}", company)
66
+ .replace("${依頼内容}", request)
67
+ .replace("${日付}", date)
68
+
69
+ const body = baseBody
70
+ .replace("${会社}", company)
71
+ .replace("${依頼内容}", request)
72
+
73
+ // Step5: 送信モードの選択
74
+ if (sendMode === "下書き作成") {
75
+ GmailApp.createDraft (recipient, subject, body, options);
76
+ } else {
77
+ GmailApp.sendEmail (recipient, subject, body, options);
78
+ ```
79
+