使用Google Apps脚本将文件作为电子邮件附件发送 [英] Sending a file as e-mail attachment with Google Apps Script

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

问题描述

是否可以使用文件上传类和 mailApp 从您的计算机中选择一个(pdf)文件(例如本教程显示),并仅临时存储(可能使用缓存)以将其发送为电子邮件附件?

Is there a way to use file upload class and mailApp to select a (pdf) file from your computer (like this tutorial shows) and stores it only temporarily (maybe using cache memory) to send it as an email attachment?

推荐答案

您所引用的示例只需做很少的修改即可完成您想要的操作... doPost中获得的变量是一个blob,即附件也是一个问题,因此将它们放在一起非常简单.

the sample you refer to needs very few modifications to do what you want... the variable you get in the doPost is a blob, the argument needed in the attachment is a blob too so it is quite straightforward to put both together.

我只在按钮上添加了文本,并在发送邮件时添加了确认消息.

I only added a text on the button and a confirmation message when the mail is sent.

请注意,文件类型将仅取决于文件的文件类型,在任何地方我们都不会将其转换为pdf,但这不是您要问的重点.

note that the file type will depend only on the filetype of the file, nowhere we convert it to pdf but that was not the point of your question.

例如,如果您上载jpeg,则其附件中将是jpeg!

if you upload a jpeg (for example) it will be a jpeg in the attachment of course !

下面的代码进行在线测试:

code below with test on line:

function doGet(e) {
   var app = UiApp.createApplication().setTitle("Upload CSV to Sheet");
   var formContent = app.createVerticalPanel();
   formContent.add(app.createFileUpload().setName('thefile'));
   formContent.add(app.createSubmitButton('send'));
   var form = app.createFormPanel();
   form.add(formContent);
   app.add(form);
   return app;
 }

 function doPost(e) {
   // data returned is a blob for FileUpload widget
   var fileBlob = e.parameter.thefile;
   MailApp.sendEmail(Session.getActiveUser(),'test pdf attachment','see attachment',{attachments: [fileBlob]});
   var app = UiApp.getActiveApplication();
   return app.add(app.createLabel('mail sent'));
 }

测试(寻求授权)

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

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