We are building a Gmail addon with Google Apps Script. We have run into a strange problem where Apps Script inserts HTML twice into the composed email. This is example code where “HELLO” is inserted twice into the email:
function insertHtml(e) {
var html = "<span>HELLO</span>"
var response = CardService.newUpdateDraftActionResponseBuilder()
.setUpdateDraftBodyAction(CardService.newUpdateDraftBodyAction()
.addUpdateContent(html, CardService.ContentType.IMMUTABLE_HTML)
.setUpdateType(CardService.UpdateDraftBodyType.IN_PLACE_INSERT))
.build();
return response;
}
This screenshot shows how “HELLO” is inserted twice:
The weird thing is that if you put a style
on <span>
, it works as intended:
function insertHtml(e) {
var html = "<span style="color: red;">HELLO</span>"
var response = CardService.newUpdateDraftActionResponseBuilder()
.setUpdateDraftBodyAction(CardService.newUpdateDraftBodyAction()
.addUpdateContent(html, CardService.ContentType.IMMUTABLE_HTML)
.setUpdateType(CardService.UpdateDraftBodyType.IN_PLACE_INSERT))
.build();
return response;
}
It also works if you use ContentType.MUTABLE_HTML
.
This looks like a bug in addons. There is no way for us to make sure that the inserted HTML does not contain <span>
without attributes.
So how can we use IMMUTABLE_HTML
?