Google Apps脚本通过电子邮件发送工作表副本

时间:2017-08-17 02:54:58

标签: email copy

我对此代码有困难。我制作副本,发送电子邮件,但电子邮件不包含附件。我很感激任何想法。

 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var MyNewBook = ss.copy("A Copy of " + ss.getName());

 var MyUser = Session.getActiveUser().getEmail()
 MailApp.sendEmail(MyUser, 'TEST', MyNewBook);

1 个答案:

答案 0 :(得分:1)

以下示例脚本怎么样? MailApp.sendEmail()的详细信息为https://developers.google.com/apps-script/reference/mail/mail-app#sendEmail(Object)

脚本:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var filename = "A Copy of " + ss.getName();
var MyNewBook = ss.copy(filename);
var MyUser = Session.getActiveUser().getEmail();
MailApp.sendEmail({
  to: MyUser,
  subject: 'TEST title',
  body: 'TEST body',
  attachments: [MyNewBook.getBlob().setName(filename)]
});