提交Google表单后发送确认电子邮件

时间:2013-05-10 14:49:33

标签: google-apps-script google-docs

我已经查看了很多资源来弄清楚我的脚本有什么问题,但没有任何工作。我正在尝试在提交Google表单后发送确认电子邮件。好像我的脚本没有正确地从表单中调用电子邮件地址 我的原始脚本来自http://acrl.ala.org/techconnect/?p=2343,我为我的表单修改了它 这就是它的样子:

function swykemailconfirm(e) {
  var userEmail = e.values[10]; //email from column K
  var firstName = e.values[2]; //first name from column C
  var lastName = e.values[1]; //last name from column B
  var test = e.values[4]; //test name from column E
 MailApp.sendEmail(userEmail, 
                    "Thank you " +firstName + lastName + "for signing up to take the " + test + "Show What You Know test. " + 
                    "Make sure you see Ms. May to get your pass. " +
                    "See you on Thursday in room 32 at 3:30." +
                    "The Math Department");
}

我在提交测试表单后收到一封包含此错误消息的电子邮件: 找不到方法(类)sendEmail(string,string)。 (第6行,文件“代码”)

在此处Google Forms Confirmation Script搜索编辑我的脚本的方法后,我使用了其中一条建议并将我的代码更改为以下内容:

function swykemailconfirm(e) {
  var userEmail = e.values["E-mail"][0];
  var firstName = e.values[2];
  var lastName = e.values[1];
  var test = e.values[4];
 MailApp.sendEmail(userEmail, 
                    "Thank you " +firstName + lastName + "for signing up to take the " + test + "Show What You Know test. " + 
                    "Make sure you see Ms. May to get your pass. " +
                    "See you on Thursday in room 32 at 3:30." +
                    "The Math Department");
}

我在提交测试表单后收到一封包含此错误消息的电子邮件: TypeError:无法从undefined中读取属性“0”。 (第2行,文件“代码”)

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

只需进行一次小修改,您的原始功能(顶部)就能正常工作。

Google Docs正在向您提供错误消息“无法找到方法(类)sendEmail(字符串,字符串)。(第6行,文件”代码“)”因为sendEmail方法需要传递三个参数:recipient(string), subject(string),body(string)。目前,您只传递两个参数:收件人和正文。请参阅文档here

将您的功能修改为以下内容,一切正常!

function swykemailconfirm(e) {
  var userEmail = e.values[10]; //email from column K
  var firstName = e.values[2]; //first name from column C
  var lastName = e.values[1]; //last name from column B
  var test = e.values[4]; //test name from column E
  MailApp.sendEmail(userEmail, 
      "Registration Confirmation Subject Line",
      "Thank you " +firstName + lastName + "for signing up to take the " + test + "Show What You Know test. " + 
      "Make sure you see Ms. May to get your pass. " +
      "See you on Thursday in room 32 at 3:30." +
      "The Math Department");
}

希望有所帮助!