2014-06-21 112 views

回答

2

你引用的示例只需要很少的修改就可以做你想做的事情......你在doPost中获得的变量是一个blob,附件中需要的参数也是一个blob,所以它很简单,一起。

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

请注意,文件类型仅取决于文件的文件类型,无处我们将其转换为pdf,但这不是您问题的要点。

如果你上传一个jpeg(例如)它将会是附件中的一个jpeg!下面

代码与测试线:

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')); 
} 

test (asking for authorization)

1
var spreadsheetFile = DriveApp.getFileById(sheetId); 
    var blob = spreadsheetFile.getAs('application/pdf'); 
    //if daysleft =1 or 0 then send mail .  
    MailApp.sendEmail(emailAddress, subject, message, { 
     name: 'Welcome mail- Perch Arbor Golf Course.pdf', 
     attachments: [blob] 
    }); 
相关问题