发送带有Google表单回复的电子邮件的脚本?

时间:2015-03-23 22:22:52

标签: javascript google-apps-script google-sheets google-form

我已经设置了Google表单,我的回复正在电子表格中记录。理想情况下,我希望通过电子邮件发送回复。

我发现了这篇文章,但看起来这个脚本只会从消息字段发送一封电子邮件。我想发送整个电子表格。

https://developers.google.com/apps-script/articles/sending_emails

有办法做到这一点吗?

1 个答案:

答案 0 :(得分:0)

提交Google表单时发送电子表格。

  • 从电子表格或表单设置表单提交触发器。
  • 决定是否要将附件作为电子邮件中的文件或文本。
  • 从电子表格或整个文件中获取数据
  • 将数据转换为电子邮件的文本或附件的文件
  • 发送电子邮件

创建在提交表单时运行的触发器:

Current Triggers

设置触发:

Set Trigger

编写代码:

function respondToFormSubmit(e) {
  Logger.log('respondToFormSubmit ran');

  fncGetContentToSend();
  fncSendEmail();
}

function fncGetContentToSend() {
  Logger.log('fncGetContentToSend ran');

  var thisSS = SpreadsheetApp.openById('your ID');
  //Convert spreadsheet to PDF
}

function fncSendEmail() {
  Logger.log('fncSendEmail ran');

 // Send an email with a file from Google Drive attached as a PDF.
 var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
 GmailApp.sendEmail('mike@example.com', 'Attachment example', 'Please see the attached file.', {
     attachments: [file.getAs(MimeType.PDF)],
     name: 'Automatic Emailer Script'
 });
};