Google Apps脚本的邮件服务应用程序中的动态邮件ID [英] Dynamic mail id in mail service app of Google apps script

查看:85
本文介绍了Google Apps脚本的邮件服务应用程序中的动态邮件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向html表单的电子邮件字段中用户指定的邮件ID发送带有默认消息的邮件。我尝试了以下无效的代码。此处需要类似URL排队。

I need to send a mail with a default message to the mail id specified by the user in the email field of an html form.I tried the below code which doesn't work.Is anything like URL queuing needed here.

<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:

Google script API:

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

}

这是我得到的错误


无效的电子邮件:
{ parameter:{}, contextPath:, contentLength:0, queryString: , parameters:{}}
(第5行,文件 Code,项目 email)

Invalid email: {"parameter":{},"contextPath":"","contentLength":0,"queryString":"","parameters":{}} (line 5, file "Code", project "email")

以下具有默认邮件ID的代码对我来说很好用

The below code which has the default mail id works fine for me

function doPost(){

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

}


推荐答案

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

You can retrieve values by adding the name attribute to the input tag. The modified HTML is as follows. In this sample, you can use the value of example@abc.com using e.parameter.addr.

<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)



Value e of 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"
  }
}

如果我误解了您问题,对不起。

If I misunderstand your question, I'm sorry.

这篇关于Google Apps脚本的邮件服务应用程序中的动态邮件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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