我有一個代碼需要在Gmail中的電子郵件正文獲取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>
主體過濾我需要:
EU: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;
}
謝謝你的幫助^^ –