1

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

Robert
  • 3,373
  • 1
  • 18
  • 34
  • Does this answer your question? [How to use HtmlService in Gmail add-on using App Script](https://stackoverflow.com/questions/47477246/how-to-use-htmlservice-in-gmail-add-on-using-app-script) – Rubén Jun 01 '20 at 18:36

1 Answers1

7

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 :

enter image description here

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.

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • Hi its possible create forms in gmail addon by using html servcies – Robert Feb 08 '18 at 05:23
  • 1
    @Robert I have never tried it for gmail add-on. So I'm not sure whether the custom forms can be created. But it's worth a try. – Tanaike Feb 08 '18 at 08:22
  • 1
    I spent quite some time on this, and confirm that it's not possible. Please see the official documentation here: https://developers.google.com/gmail/add-ons/guides/restrictions (You can't design a custom UI for your add-on using HTML, CSS and Javascript.) – Walty Yeung Mar 07 '19 at 10:47