首页 > 解决方案 > 谷歌应用脚​​本,TextOutput 不返回消息

问题描述

故事:我正在测试一个谷歌应用程序脚本,它接收一个文件并向收件人发送一封电子邮件,其中包含一个文件内容作为邮件的正文。我还想让发件人/用户知道“电子邮件发送成功”

问题:一切正常,直到到达最后一行,

return ContentService.createTextOutput("sent successfully!!!");

它应该将成功消息返回给发件人。但它发送http状态错误[302]。我正在使用 dio 包发送 http post 请求。我也单独测试了返回线,它工作正常。

function doPost(e) {
  var blob = Utilities.newBlob(Utilities.base64DecodeWebSafe(e.parameter.file),e.parameter.contentType,e.parameter.fileName);
  var body = blob.getDataAsString();
  MailApp.sendEmail("testEmail@gmail.com", "this is a test subject", body);
  return ContentService.createTextOutput("sent successfully!!!"); //doesnt work
}

这段代码工作得很好:

function doGet() {
  return ContentService.createTextOutput("hello world!");
}

我究竟做错了什么?

标签: google-apps-script

解决方案


e.parameterGET通常用于GET请求的参数

你应该使用e.postData


推荐阅读