google script use html service in gmail addon

心不动则不痛 提交于 2020-06-10 02:10:29

问题


I've try to create simple form in gmail addon,

how to use html service

The below code,i have tried,

function buildAddOn(e) {
  var accessToken = e.messageMetadata.accessToken;
  GmailApp.setCurrentMessageAccessToken(accessToken);
  var test_card = doGet()
  cards.push(test_card);
  return cards;
}
function doGet() {
   return HtmlService.createHtmlOutput('<b>Hello, world!</b>');
 }

Thanks in advance


回答1:


I understood that you want to use HTML at Gmail add-on. If my understanding is correct, how about these sample scripts?

Sample script 1 :

function buildAddOn() {
  var html = HtmlService.createTemplate('<b>Hello, world!</b>').evaluate().getContent();
  return CardService.newCardBuilder()
  .setHeader(CardService.newCardHeader().setTitle('sample'))
  .addSection(CardService.newCardSection().addWidget(CardService.newKeyValue().setContent(html)))
  .build();
}

Sample script 2 :

Code.gs
function buildAddOn() {
  var html = HtmlService.createTemplateFromFile("index").evaluate().getContent();
  return CardService.newCardBuilder()
  .setHeader(CardService.newCardHeader().setTitle('sample'))
  .addSection(CardService.newCardSection().addWidget(CardService.newKeyValue().setContent(html)))
  .build();
}
index.html
<b>Hello, world!</b>

Result :

Note :

  • As a sample, Manifests was used from Quickstart.
  • This is a very simple script. So please modify it for your environment.

If I misunderstand your question, I'm sorry.



来源:https://stackoverflow.com/questions/48636518/google-script-use-html-service-in-gmail-addon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!