首页 > 解决方案 > 从 webapp 调用的函数不发送电子邮件

问题描述

我在使用 Google 脚本时遇到问题。

我正在尝试做一个开放式问卷调查,允许匿名文件上传到我的谷歌驱动器上的特定文件夹,然后向我发送一封通知电子邮件到我的邮件。它可以正常上传文件,但未发送电子邮件。

在调试模式下,它发送了电子邮件。

这是我的代码:

<form id="myForm">
    <input type="text" name="myName" placeholder="Su Nombre..">
    <input type="file" name="myFile">
    <input type="submit" value="Subir Archivo" 
           onclick="this.value='subiendo..';
                    google.script.run.withSuccessHandler(fileUploaded)
                    .uploadFiles(this.parentNode);
                    return false;">
</form>

和谷歌脚本文件:

function doGet(e) {
  return HtmlService.createHtmlOutputFromFile('form.html');
}

function uploadFiles(form) {
  try {
    var folder = DriveApp.getFolderById(/*folder id*/);
    var blob = form.myFile;    
    var file = folder.createFile(blob);     

    file.setDescription("Subido Por " + form.myName);

    // email
    var asunto = "Testing attaching file";
    var correo = /*my email address*/;
    var options = {attachment : [form.MyFile]};    

    MailApp.sendEmail(correo, asunto, emailBody, options);

    return "Archivo Subido Con Exito " + file.getUrl();
  } 
  catch (error) { 
     return error.toString(); 
  }
}

标签: google-apps-scriptweb-applications

解决方案


推荐阅读