我有一个代码可以捕获电子邮件并将其放入电子表格并将此电子邮件放入其他标签中,它可以正常工作,但我将范围设置在 0 到 50 之间,当我查看电子邮件出现超过 50 封电子邮件的标签时,为什么这发生了?
谢谢
代码
function get_emails() {
var sheet = SpreadsheetApp.getActiveSheet();
var label_pending = GmailApp.getUserLabelByName('Fale Conosco/Contato');
var label_done = GmailApp.getUserLabelByName('Teste Done');
var threads = label_pending.getThreads(0, 50);
var index = getColIndexByName('Conteúdo');
for (var t in threads) {
var thread = threads[t];
var html = thread.getMessages()[0].getBody();
html=html.replace(/<\/div>/ig, '\n');
html=html.replace(/<\/li>/ig, '\n');
html=html.replace(/<li>/ig, ' *');
html=html.replace(/<\/ul>/ig, '\n');
html=html.replace(/<\/p>/ig, '\n');
html=html.replace(/<br\/?>/ig, '\n');
html=html.replace(/<[^>]+>/ig, '');
sheet.getRange((sheet.getLastRow() + 1), index).setValue(html);
thread.removeLabel(label_pending);
thread.addLabel(label_done);
}
return 0;
}
function getColIndexByName(colName) {
var sheet = SpreadsheetApp.getActiveSheet();
var numColumns = sheet.getLastColumn();
var row = sheet.getRange(1, 1, 1, numColumns).getValues();
for (i in row[0]) {
var name = row[0][i];
if (name == colName) {
return parseInt(i) + 1;
}
}
return -1;
}