Google Apps脚本的邮件服务应用中的动态邮件ID

时间:2017-09-26 10:16:23

标签: javascript email google-apps-script

我需要将一个带有默认消息的邮件发送到用户在html表单的电子邮件字段中指定的邮件ID。我尝试了下面的代码,它不起作用。这里需要像URL排队这样的东西。

<form method="POST" action="https://script.google.com/macros/s/AKfycbwIzz6c_PL7D9ioCrzDRvTdmBj2nZR-2ekUZ9pjgHeG3b3Simg/exec">
    <label for="mail">Enter your mailID:</label>
    <input type="email" id="mail" required>
    <input type="submit">
</form>

Google脚本API:

 function doPost(e){
  var addr = JSON.stringify(e);
  MailApp.sendEmail(addr,
                   "Recovery email for TracerSC",
                   "Your one time password ");

}

这是我得到的错误

  

电子邮件无效:   { “参数”:{} “的contextPath”: “”, “CONTENTLENGTH”:0 “的queryString”: “”, “参数”:{}}   (第5行,文件“代码”,项目“电子邮件”)

以下具有默认邮件ID的代码可以正常使用

function doPost(){

  MailApp.sendEmail("example@abc.com",
                   "Recovery email for TracerSC",
                   "Your one time password ");

}

1 个答案:

答案 0 :(得分:1)

您可以通过将name属性添加到输入标记来检索值。修改后的HTML如下。在此示例中,您可以使用example@abc.com使用e.parameter.addr的值。

修改后的HTML:

<form method="POST" action="https://script.google.com/macros/s/AKfycbwIzz6c_PL7D9ioCrzDRvTdmBj2nZR-2ekUZ9pjgHeG3b3Simg/exec">
    <label for="mail">Enter your mailID:</label>
    <input type="email" id="mail" name="addr" required>
    <input type="submit">
</form>

e

的值doPost(e)
{
  "parameter": {
    "addr": "example@abc.com"
  },
  "contextPath": "",
  "contentLength": 22,
  "queryString": "",
  "parameters": {
    "addr": [
      "example@abc.com"
    ]
  },
  "postData": {
    "type": "application/x-www-form-urlencoded",
    "length": 22,
    "contents": "addr=example%40abc.com",
    "name": "postData"
  }
}

如果我误解了你的问题,我很抱歉。

相关问题