代码之家  ›  专栏  ›  技术社区  ›  Jakob Christensen

使用IMMUTABLE_HTML在邮件中插入两次HTML

  •  0
  • Jakob Christensen  · 技术社区  · 2 年前

    我们正在使用Google Apps Script构建一个Gmail插件。我们遇到了一个奇怪的问题,Apps Script在编写的电子邮件中插入了两次HTML。这是在电子邮件中插入两次“HELLO”的示例代码:

    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;
    }
    

    "HELLO" inserted twice

    奇怪的是,如果你放一个 style <span>

    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;
    }
    

    enter image description here

    如果你使用它,它也会起作用 ContentType.MUTABLE_HTML .

    这看起来像是插件中的一个bug。我们无法确保插入的HTML不包含 <

    那么,我们如何使用 IMMUTABLE_HTML ?

    0 回复  |  直到 2 年前