Google 文档的 Gmail 发送的 PDF 附件是空白的
PDF attachment sent with Gmail of Google doc is blank
我的目标是在 Gmail 附件中附加 google 文档的 PDF 版本。我已经使用应用程序脚本生成了文档并将其保存在云端硬盘中的一个文件夹中。电子邮件以 PDF 格式发送,但 pdf 文件不包含任何内容(完全空白)。我正在使用的相关代码:
var blob = DriveApp.getFileById(docID).getAs("application/pdf"); // problem line?
GmailApp.sendEmail(clientEmail, 'subject', 'Please see the attached file.', {
attachments: [blob],
name: 'Automatic Emailer Script',
});
而且我已经尝试在此处使用 Google 中的代码:
var file = DriveApp.getFileById(docID);
MailApp.sendEmail(clientEmail, 'Attachment example', 'Please see attached.', {
name: 'Automatic Emailer Script',
attachments: [file.getAs(MimeType.PDF)] // something going on here?
});
在这两种情况下,我都收到了一封带有正确文件名的 PDF 附件的电子邮件,但它完全是空白的,并且不包含据称生成的 (google 文档) 文档的内容。创建 blob 时我是否遗漏了什么?是否有我需要正确生成 blob 的文档特定参数?
我显然遗漏了一些东西 - 如果很明显,我很抱歉!
解决方案已在此 post:
上找到
Google apps script: Create a new document and send it using Gmail
文档必须保存一次才能通过电子邮件发送。
在脚本上使用函数 saveAndClose() 可以在发送文档之前保存文档,以防您要发送新生成的文档。
我的目标是在 Gmail 附件中附加 google 文档的 PDF 版本。我已经使用应用程序脚本生成了文档并将其保存在云端硬盘中的一个文件夹中。电子邮件以 PDF 格式发送,但 pdf 文件不包含任何内容(完全空白)。我正在使用的相关代码:
var blob = DriveApp.getFileById(docID).getAs("application/pdf"); // problem line?
GmailApp.sendEmail(clientEmail, 'subject', 'Please see the attached file.', {
attachments: [blob],
name: 'Automatic Emailer Script',
});
而且我已经尝试在此处使用 Google 中的代码:
var file = DriveApp.getFileById(docID);
MailApp.sendEmail(clientEmail, 'Attachment example', 'Please see attached.', {
name: 'Automatic Emailer Script',
attachments: [file.getAs(MimeType.PDF)] // something going on here?
});
在这两种情况下,我都收到了一封带有正确文件名的 PDF 附件的电子邮件,但它完全是空白的,并且不包含据称生成的 (google 文档) 文档的内容。创建 blob 时我是否遗漏了什么?是否有我需要正确生成 blob 的文档特定参数?
我显然遗漏了一些东西 - 如果很明显,我很抱歉!
解决方案已在此 post:
上找到Google apps script: Create a new document and send it using Gmail
文档必须保存一次才能通过电子邮件发送。
在脚本上使用函数 saveAndClose() 可以在发送文档之前保存文档,以防您要发送新生成的文档。