简体   繁体   English

使用Google Apps脚本将Google驱动器中的pdf附加到电子邮件

[英]Attach a pdf from google drive to an email using google apps script

I'm using a custom created google apps script to send out some emails. 我正在使用自定义创建的Google Apps脚本发送一些电子邮件。 I have a PDF in my google drive that I am trying to attach to an email but it is not working. 我的Google驱动器中有一个PDF,我尝试将其附加到电子邮件中,但不起作用。 I keep on getting the error "Document is missing (perhaps it was deleted?)" 我不断收到错误消息“文档丢失(也许它已被删除?)”

Here is my full code... 这是我的完整代码...

    function sendDetails(e) {
var itemURL = 'https://docs.google.com/file/d/0Bw7JWLKeRBKASUFldGM1RTRIaFE/edit';
var docName = DocumentApp.openByUrl(itemURL).getName();
}

Note that the above PDF is a publicly accessible PDF file that anyone can get to. 请注意,以上PDF是任何人都可以访问的可公开访问的PDF文件。 I know it exists but it's not allowing me to access it. 我知道它存在,但是不允许我访问它。 All that I am trying to do is take the file and attach it to an email. 我要做的就是拿走文件并将其附加到电子邮件中。 There is obviously more to my code than the about but I trimmed down just to that to try to narrow the error and no such luck. 我的代码显然比“ about”更多,但我只是为了缩小错误而进行了精简,没有运气。 Any help would be greatly appreciated. 任何帮助将不胜感激。

DocumentApp deals with Google Documents - Google's WordPad-like editor. DocumentApp处理Google Documents(类似于WordPad的Google编辑器)。 Since the file in question is a PDF, it's not available to DocumentApp. 由于相关文件为PDF,因此DocumentApp无法使用。

Instead, you should be using DriveApp . 相反,您应该使用DriveApp Additionally, since there is no DriveApp method to open a file by URL, you need to use DriveApp.getFileById() . 此外,由于没有通过URL打开文件的DriveApp方法,因此需要使用DriveApp.getFileById() (The ID is "0Bw7JWLKeRBKASUFldGM1RTRIaFE" in your example.) (在您的示例中,该ID为"0Bw7JWLKeRBKASUFldGM1RTRIaFE" 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Apps Script - 将带有样式的 HTML 转换为 PDF 并附加到电子邮件 - 从 HTML 创建 PDF blob - Google Apps Script - Convert HTML with styling to PDF and attach to an email - Create a PDF blob from HTML 使用共享驱动器中的 Apps 脚本附加 PDF - Attach PDF using Apps Script from Shared Drive 发送带有附件的电子邮件,并使用Google Apps脚本保存在Google云端硬盘中 - Send an email with attachment and save in Google Drive using Google Apps Script 使用Apps脚本从Google云端硬盘将图像插入Google表格 - Inserting Image into Google Sheets from Google Drive using Apps Script Google脚本-无法将Google云端硬盘中的PNG文件附加到表单电子邮件中 - Google script - Can't attach a PNG file from Google Drive to form email 将 Google Drive 文件和工作表 PDF 附加到同一个 email - attach both Google Drive file and sheet PDF to the same email 如何在 Apps 脚本中使用 sendMail 功能附加 Google Drive 文件? - How to Attach Google Drive File with sendMail Function in Apps Script? Google Apps脚本-通过电子邮件发送pdf - Google Apps Script - send pdf in email 谷歌表格应用程序脚本,如何格式化保存到谷歌驱动器的 pdf? - Google sheets apps script, how to format a pdf saved to google drive? Google Apps脚本在Google驱动器中发送带有附件jpg文件的电子邮件 - Google apps script sends email with attached jpg file in google drive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM