5

I want to embed a Google form in an email and send it with MailApp. I'm attempting to use code found at: https://stackoverflow.com/a/23671529/4305236:

var form = FormApp.create('New Form');
....
var url = form.getPublishedUrl();
var response = UrlFetchApp.fetch(url);
var htmlBody = HtmlService.createHtmlOutput(response).getContent();
    MailApp.sendEmail({
    to: email,
    subject: subject,
    htmlBody: htmlBody,
  });
...

The logs show all the html for the form.

However, when I run the code, the email just looks like text, with the links at bottom. When I "show original" in the email, though, all that html for the form seems to be there, like in the log...

Would greatly appreciate any help.

What generated form looks like, want this to be embedded in email: What generated form looks like, want this to be embedded in email

What they are getting instead: What they are getting instead

Community
  • 1
  • 1
tmkiefer
  • 215
  • 1
  • 2
  • 10

1 Answers1

0

Answered here: https://stackoverflow.com/a/60749897/3383907.

Copy/pasting for history purposes:

When Google sends the form to folks directly and embeds the form in the email they are using their new offering called AMP. You can read more about it here:

The code you're using gets the raw HTML of the form as it would be rendered for a user in a browser. This code is not in AMP format. Ergo it will not do what you want.

If you want that AMP experience you will need to create the AMP email yourself.

I don't think FormApp has a programatic way to send the form to folks, like you can from https://docs.google.com/forms/.

I hope that helps.

IMTheNachoMan
  • 5,343
  • 5
  • 40
  • 89