Google Apps脚本-通过电子邮件发送pdf [英] Google Apps Script - send pdf in email

查看:75
本文介绍了Google Apps脚本-通过电子邮件发送pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个发送电子邮件的脚本.我想进行设置,以使电子邮件发送时带有我的Google驱动器中的pdf附件.该文件的名称为pdfholder.pdf

I have a script that sends an email. I would like to set it up so that the email is sent with a pdf attachment that is in my google drive. The name of the file is pdfholder.pdf

这是当前有效(不带附件)并发送电子邮件的代码

Here is the code that is currently working (without attachment), and sending emails

MailApp.sendEmail(userEmail, subject, message);

这是不起作用(带有附件)并且不发送电子邮件的代码

Here is the code that is not working (with the attachment), and not sending emails

var file = DocsList.getFileById('pdfholder');
MailApp.sendEmail(userEmail, subject, message, {attachments:file});

关于如何使它工作的任何想法?我是Google Apps脚本的新手,所以非常感谢您进行简单/详尽的解释.谢谢!

Any ideas on how to get this working? I am new to google apps scripting so simple/thorough explanations would be much appreciated. Thanks!

推荐答案

可选参数附件所需的参数是一个数组(如

The argument needed for the optional argument attachment is an array (as clearly shown in the documentation). This is to allow for easy handling of multiple attached files. In you case it will be an array of one single element : [file] so your final code would (indeed) be

MailApp.sendEmail(userEmail, subject, message, {attachments:[file]});

这篇关于Google Apps脚本-通过电子邮件发送pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆