Email 谷歌应用程序脚本-在电子邮件中发送pdf
我有一个发送电子邮件的脚本。我想设置它,使电子邮件发送与pdf附件是在我的谷歌驱动器。文件名为pdfholder.pdf 以下是当前正在运行的代码(无附件)和发送电子邮件的代码Email 谷歌应用程序脚本-在电子邮件中发送pdf,email,google-apps-script,gmail,Email,Google Apps Script,Gmail,我有一个发送电子邮件的脚本。我想设置它,使电子邮件发送与pdf附件是在我的谷歌驱动器。文件名为pdfholder.pdf 以下是当前正在运行的代码(无附件)和发送电子邮件的代码 MailApp.sendEmail(userEmail, subject, message); var file = DocsList.getFileById('pdfholder'); MailApp.sendEmail(userEmail, subject, message, {attachments:file})
MailApp.sendEmail(userEmail, subject, message);
var file = DocsList.getFileById('pdfholder');
MailApp.sendEmail(userEmail, subject, message, {attachments:file});
以下是不工作的代码(带有附件),并且不发送电子邮件
MailApp.sendEmail(userEmail, subject, message);
var file = DocsList.getFileById('pdfholder');
MailApp.sendEmail(userEmail, subject, message, {attachments:file});
有什么办法让它工作吗?我对谷歌应用程序脚本还不熟悉,如果能简单/透彻地解释一下,我将不胜感激。谢谢 可选参数附件所需的参数是一个数组(如中所示)。 这是为了便于处理多个附加文件。在您的情况下,它将是一个由单个元素组成的数组:[file] 因此,您的最终代码(实际上)是
可选参数附件所需的参数是一个数组(如中所示)。 这是为了便于处理多个附加文件。在您的情况下,它将是一个由单个元素组成的数组:[file] 因此,您的最终代码(实际上)是
官方文件中也有一个用于此目的的示例: // Send an email with two attachments: a file from Google Drive (as a PDF) and an HTML file. var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz'); var blob = Utilities.newBlob('Insert any HTML content here', 'text/html', 'my_document.html'); MailApp.sendEmail('mike@example.com', 'Attachment example', 'Two files are attached.', { name: 'Automatic Emailer Script', attachments: [file.getAs(MimeType.PDF), blob] }); //发送包含两个附件的电子邮件:一个来自Google Drive的文件(PDF格式)和一个HTML文件。 var file=DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz'); var blob=Utilities.newBlob('Insert any HTML content here'、'text/HTML'、'my_document.HTML'); MailApp.sendmail('mike@example.com“,”附件示例“,”已附加两个文件。“{ 名称:“自动电子邮件程序脚本”, 附件:[file.getAs(MimeType.PDF),blob] }); 见:
官方文件中也有一个用于此目的的示例: // Send an email with two attachments: a file from Google Drive (as a PDF) and an HTML file. var file = DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz'); var blob = Utilities.newBlob('Insert any HTML content here', 'text/html', 'my_document.html'); MailApp.sendEmail('mike@example.com', 'Attachment example', 'Two files are attached.', { name: 'Automatic Emailer Script', attachments: [file.getAs(MimeType.PDF), blob] }); //发送包含两个附件的电子邮件:一个来自Google Drive的文件(PDF格式)和一个HTML文件。 var file=DriveApp.getFileById('1234567890abcdefghijklmnopqrstuvwxyz'); var blob=Utilities.newBlob('Insert any HTML content here'、'text/HTML'、'my_document.HTML'); MailApp.sendmail('mike@example.com“,”附件示例“,”已附加两个文件。“{ 名称:“自动电子邮件程序脚本”, 附件:[file.getAs(MimeType.PDF),blob] }); 见:
“无意冒犯,但这类问题需要的不仅仅是一行代码……对于“非专家”提问者来说,一句解释和/或一个指向文档的链接通常是必要的。”——Serge insas/William Chiquito说:完全同意。不幸的是,我没有足够的时间来给出一个更详细的答案,所以我只把代码。在未来的场合,我们将避免这种回答。非常感谢。我删除了我的答案。“无意冒犯,但这类问题需要的不仅仅是一行代码……对于“非专家”提问者来说,一句解释和/或一个指向文档的链接通常是必要的。”——Serge insas/William Chiquito说:完全同意。不幸的是,我没有足够的时间来给出一个更详细的答案,所以我只把代码。在未来的场合,我们将避免这种回答。非常感谢。我删除了我的答案。