简体   繁体   English

使用 Apps 脚本在 Gmail 中嵌入 Google 表单

[英]Embed Google Form in Gmail using Apps Script

I'm trying to use Apps script to embed a prefilled Form in an email.我正在尝试使用 Apps 脚本在电子邮件中嵌入预先填写的表单。 The emails will only be sent to Gmail users.电子邮件只会发送给 Gmail 用户。 I want something that works the same as pressing the 'include form in email' option when manually emailing a form.我想要一些与手动通过电子邮件发送表单时按“在电子邮件中包含表单”选项相同的功能。

I've successfully created the prefilledUrl and used UrlFetchApp and HtmlService to get the Html from the form and send email.我已经成功地创建了prefilledUrl和使用UrlFetchAppHtmlService从形式和发送电子邮件获得HTML。

But when it arrives it looks like the screenshot below and user can not submit.但是当它到达时,它看起来像下面的屏幕截图,用户无法提交。 嵌入在电子邮件中的表单的屏幕截图

A stripped down version of the code I am using is the following:我正在使用的代码的精简版本如下:

var prefilledForm = 'prefilledForm link here');
Logger.log(prefilledForm);

var subject = 'Message from Office';
var response = UrlFetchApp.fetch(prefilledForm);
var htmlBody = HtmlService.createHtmlOutput(response).getContent();

var body = 'Dear '+mName+',\n\n'+mMessage+'\nPlease acknowledge by submitting the form below.\nRegards,\nSchool Office';

GmailApp.sendEmail(eEmail,subject,body,{
  noReply:true,
  htmlBody: htmlBody
});

Is there anyway to embed the form in an email just like it does when you select 'include form in email' like the screenshot below?无论如何,当您选择“在电子邮件中包含表单”(如下面的屏幕截图)时,是否可以将表单嵌入到电子邮件中?

在此处输入图片说明

  1. Send the form to yourself with the form included in the email.将表格与电子邮件中包含的表格一起发送给您自己。
  2. Open Gmail in the browser, press F12.在浏览器中打开 Gmail,按 F12。 Find the div of the form in the email body.在电子邮件正文中找到表单的 div。 在此处输入图片说明
  3. Paste the div code to the body of the Apps Script HTML file.将 div 代码粘贴到 Apps 脚本 HTML 文件的正文中。 Or paste it to email HTML body in your script, I didn't test it.或者将其粘贴到脚本中的电子邮件 HTML 正文中,我没有对其进行测试。 在此处输入图片说明
  4. Send the email with the above HTML file, you should be able to get a similar result as below.发送带有上述 HTML 文件的电子邮件,您应该能够获得如下类似的结果。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM