我有一个代码可以获取 Gmail 中的电子邮件正文
但是正文带有“HTML标签”,我如何过滤掉这些“标签”?
例子:
身体:
<span><span style="font-weight:bold" dir="ltr">eu</span>:
<a href="http://neuhaus.com.br" target="_blank">neuhaus.com.br</a>
D6477233ACC7C56D</span><br>
我需要过滤的身体:
欧盟:neuhaus.com.br D6477233ACC7C56D
代码:
function processPending() {
var label_pending = GmailApp.getUserLabelByName('Teste');
var label_done = GmailApp.getUserLabelByName('TesteDone');
var sheet = SpreadsheetApp.getActiveSheet();
var rowstart = (sheet.getLastRow() + 1)
var threads = label_pending.getThreads();
for (var t in threads) {
var thread = threads[t];
var message = thread.getMessages()[0];
var messbody = message.getBody();
thread.removeLabel(label_pending);
thread.addLabel(label_done);
sheet.getRange(rowstart, getColIndexByName('Conteúdo')).setValue(messbody);
rowstart++;
}
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;
}