【发布时间】:2014-10-29 22:48:20
【问题描述】:
我正在尝试创建一个 Google AppScript,它可以每天通过电子邮件将 Google 电子表格作为 PDF 发送出去。
以下是我根据在 https://developers.google.com/apps-script/reference/mail/mail-app#sendEmail(String,String,String) 找到的示例创建的脚本
当我尝试运行下面的脚本时,我收到错误“访问被拒绝:DriveApp。(第 3 行,文件“代码”)”
我应该更改什么以避免收到此错误?
或者有没有其他方法可以让谷歌电子表格每天以 PDF 格式通过电子邮件发送出去?
function emailSiteBody() {
// Send an email with attachment: a file from Google Drive (as a PDF).
var file = DriveApp.getFileById('xxxxxt9Qg5uTkTxxxxxxxxxDkRJVZ9OSYCWDEHGxxxxx');
MailApp.sendEmail('first.last@domain.com', 'Attachment example', 'file attached.', {
name: 'Automatic Emailer Script',
attachments: [file.getAs(MimeType.PDF)]
});
}
【问题讨论】:
-
该代码对我来说很好用。检查运行脚本的帐户至少对您正在使用的文件具有读取权限。
-
See this SO question 解释为什么您会收到“拒绝访问”错误。基本上,您必须在 Google Apps 管理控制台的云端硬盘设置中启用“允许用户安装 Google Drive Apps”选项。
标签: email pdf google-apps-script google-sheets