Google Apps脚本 - 自动发送电子邮件和共享

时间:2014-10-10 16:53:36

标签: google-apps-script

我正在尝试编写一个小型Google Apps脚本,该脚本将发送确认电子邮件,并在完成表单后自动与登录用户共享文件夹。这是脚本:

function formSubmitReply(e) {
  MailApp.sendEmail({
    to: Session.getActiveUser().getEmail(),
    subject: "Keuka College Brand Download Center",
    htmlBody: 
              "<p>Thank you for requesting access to the Keuka College Brand Download Center. Your access has been approved.</p>" +
              "<p>You may access the download center by <a href='https://drive.google.com/a/keuka.edu/folderview?id=0B856ZeGoaGT_MG5BMEtEVGwzYkk&usp=sharing'>using this link,</a> " +
              "visiting <a href='http://brand.keuka.edu'>Keuka College Brand Central,</a> or through your Google Drive.</p><p>Please contact the Office of Marketing and Communications " +
              "with any questions you may have.</p>",
    name: "Keuka College",
    replyTo: "marketing@keuka.edu"
  });

 var folder = DocsList.getFolder('Brand Download Center');
 folder.addViewer(Session.getActiveUser());

}​

这似乎有效,除了它一直通过电子邮件发送给我 - 而不是正在填写表单的用户。我不确定它是否正确分享。

有人可以提供一些见解吗?这是我第一次使用Google Apps脚本。

1 个答案:

答案 0 :(得分:0)

Session.getActiveUser()是使用表单编辑器的用户和创建调用此函数的触发器的用户。

您希望我们填写表单的用户。

查看文档here,了解如何检索该值。请注意,它将only be available if you are in a domain


编辑抱歉延迟

以下示例代码显示如何在formApp中获取表单响应者(仅适用于GAFE或GA业务)

它会向您发送一封邮件,其中包含最后一个表单提交者的名称(不要忘记创建一个可安装的onEdit触发器来测试它)。

function onSubmit(){
  var form = FormApp.getActiveForm();
  var formResponses = form.getResponses();
  var lastResponse = formResponses[formResponses.length-1];
  var user = lastResponse.getRespondentEmail()
  var userString = 'user = '+user;
  MailApp.sendEmail(Session.getActiveUser().getEmail(),'form submission report',userString);
}