Gmail 메일을 스프레드 시트로 가져 오는 스크립트를 작성했습니다. 받은 편지함 규칙은 Gmail 라벨 "가져 오기 대기 중"으로 이동하고 스크립트는 메일을 처리 한 다음이 라벨을 제거하고 가져온 라벨에 추가합니다.스레드의 모든 메일 가져 오기 방지하기
"가져 오기 대기 중"레이블로 전자 메일을 받으면 레이블이 전체 스레드에 적용된 것처럼 보입니다. 메시지는 이전에 가져온 메시지와 동일한 제목을 가지므로 스레드에서 이미 가져온 다른 모든 메시지를 가져옵니다.
여기 내 스크립트입니다 :
var importedCount = 0;
var label = GmailApp.getUserLabelByName('Monitor/AwaitingImport');
var threads = label.getThreads(0,50); // An array of threads (limit set to 50, this could be increased)
if (threads.length != 0) { // If a thread exists
for (var i = 0; i < threads.length; i++) { // for each thread in the label
var threadsubject = threads[i].getFirstMessageSubject();
if (threadsubject.match(/(Check In)/)) { // if the subject contains "Check In"
var messages = threads[i].getMessages(); // get ALL the messages
for (var j = 0; j < messages.length; j++) { // for each message
var body = messages[j].getPlainBody();
// Get key:value pairs from email into an array
var array = body.trim().split("\n");
var newArray = [];
for (k = 0; k < array.length; k++) {
newArray = newArray.concat(array[k].toString().split("="));
}
// Push other data to array that isn't in body of email
newArray.push("GmailMessageID", messages[j].getId());
newArray.push("MessageDate", messages[j].getDate());
// Create object
var newObj = {};
for (var l =0 ; l< newArray.length ; l++) {
if (l%2 == 0){
newObj[newArray[l]] = newArray[l+1];
}
}
// Now insert object as record into the spreadsheet
insertRecordWithAnyFieldsIntoAnySheet('Incoming Logs', newObj, true);
}
// Finally remove the label from this message, mark it as read, and update the importedCount (for logging)
threads[i].removeLabel(GmailApp.getUserLabelByName('Monitor/AwaitingImport'));
threads[i].addLabel(GmailApp.getUserLabelByName('Monitor/Imported'));
importedCount++;
}
}
}
SpreadsheetApp.getActiveSpreadsheet().toast(importedCount + ' messages imported');
어떻게 수입되는 스레드의 모든 메시지를 방지하고, 방금 수신 된 하나를 가져올 수 있습니까?
나는이 이미 시트로 가져올 메시지의 수천의 리소스를 많이 검색을 포함하는 것처럼, 이미 Gmail의 메시지 ID를 사용하여 수입 메시지에 대해 수신 메시지를 확인하지 않으 .
이 잠재적으로 다른를 추가하여, 마지막으로 내가 읽지 않은 메시지를 가져올 시도
- 수입되지 않은 다른 메시지를 그리워 때문에, 스레드에서 마지막 메시지를 가져 오지 않는다 스크립트에 대한 조건 (즉,
if (messages[j].isRead())
을), (위의 코드에서 도시하지 않음) 읽을 수 있지만이 여전히 기본 Gmail이 작품으로 스레드