質問編集履歴
2
文章の加筆
test
CHANGED
File without changes
|
test
CHANGED
@@ -136,7 +136,7 @@
|
|
136
136
|
|
137
137
|
```
|
138
138
|
|
139
|
-
|
139
|
+
2020050423時追記:量指定子変更
|
140
140
|
|
141
141
|
```GAS
|
142
142
|
|
1
コード追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -135,3 +135,105 @@
|
|
135
135
|
}
|
136
136
|
|
137
137
|
```
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
```GAS
|
142
|
+
|
143
|
+
function contact_Gmail() {
|
144
|
+
|
145
|
+
var rowNumber = 2;
|
146
|
+
|
147
|
+
var mysheetname = 'Gmail解析_' + Utilities.formatDate(new Date(), 'JST', 'yyyyMMddHHmmss');
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
var GmailSS = SpreadsheetApp.create(mysheetname);
|
152
|
+
|
153
|
+
var mySheet = GmailSS.getSheets()[0];
|
154
|
+
|
155
|
+
mySheet.setName(mysheetname);
|
156
|
+
|
157
|
+
mySheet.getRange(1,1).setValue("日時");
|
158
|
+
|
159
|
+
mySheet.getRange(1,2).setValue("送信元");
|
160
|
+
|
161
|
+
mySheet.getRange(1,3).setValue("件名");
|
162
|
+
|
163
|
+
mySheet.getRange(1,4).setValue("本文");
|
164
|
+
|
165
|
+
mySheet.getRange(1,5).setValue("ご予約");
|
166
|
+
|
167
|
+
mySheet.getRange(1,6).setValue("お名前");
|
168
|
+
|
169
|
+
mySheet.getRange(1,7).setValue("電話番号");
|
170
|
+
|
171
|
+
mySheet.getRange(1,8).setValue("メールアドレス");
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
var newfolder = DriveApp.createFolder(mysheetname);
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
var searchQuery = 'subject:("finalized") ';
|
180
|
+
|
181
|
+
var threads = GmailApp.search(searchQuery, 0, 200);
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
var mymsg=[];
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
var msgs = GmailApp.getMessagesForThreads(threads);
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
for(var i = 0; i < msgs.length; i++) {
|
194
|
+
|
195
|
+
mymsg[i]=[];
|
196
|
+
|
197
|
+
for(var j = 0; j < msgs[i].length; j++) {
|
198
|
+
|
199
|
+
mymsg[i][0] = msgs[i][j].getDate();
|
200
|
+
|
201
|
+
mymsg[i][1] = msgs[i][j].getFrom();
|
202
|
+
|
203
|
+
mymsg[i][2] = msgs[i][j].getSubject();
|
204
|
+
|
205
|
+
var nbsp = String.fromCharCode(160);
|
206
|
+
|
207
|
+
mymsg[i][3] = msgs[i][j].getPlainBody().replace(/<("[^"]*"|'[^']*'|[^'">])*>|nbsp/g,'').replace(/&; | /g,'').substring(0,50000);
|
208
|
+
|
209
|
+
mymsg[i][4] = fetchData(mymsg[i][3],'Appointments:','Name:');
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
if(mymsg.length>0){
|
216
|
+
|
217
|
+
GmailSS.getSheets()[0].getRange(2, 1, i, 5).setValues(mymsg); //シートに貼り付け
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
function fetchData(str, pre, suf) {
|
226
|
+
|
227
|
+
var reg = new RegExp(pre + '.*?' + suf,'m');
|
228
|
+
|
229
|
+
var data = str.match(reg)[0]
|
230
|
+
|
231
|
+
.replace(pre, '')
|
232
|
+
|
233
|
+
.replace(suf, '');
|
234
|
+
|
235
|
+
return data;
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
```
|