google 侧边栏和应用程序脚本发送电子邮件组成主题和正文

google sidebar & app script sending email composing subject and body

我需要帮助来设置 google 工作表边栏以接受主题和电子邮件正文的输入?

我已经能够让一个工作,但不能同时工作。下面的代码....

<head>
    <title>Test Page</title>
</head>

<body>
    <form>
    Email Subject:<br>
        <input type="text" name="subject" size="36">
    Email Message:<br>
        <textarea name="body" rows="15" cols="37"style="Left"></textarea>
        <p>
        <input type="button" onClick="formSubmit()" value="Submit" />
        <input type="button" onClick="google.script.host.close()" value="Cancle" />

    </form>
</body>
<script type="text/javascript">
    function formSubmit() {
        google.script.run.sendEmail(document.forms[0],document.forms[1]);
    }
</script>

您想使用 GAS 端 sendEmail() 的文本框和文本区域中的值。如果我的理解是正确的,这个修改怎么样?我认为你的情况有几个答案。所以请将此视为其中之一。

修改点:

  • <p>没有</p>
  • 它使用 this.parentNode 来检索值。

修改后的脚本:

<head>
    <title>Test Page</title>
</head>

<body>
    <form>
    Email Subject:<br>
        <input type="text" name="subject" size="36">
    Email Message:<br>
        <textarea name="body" rows="15" cols="37"style="Left"></textarea>
        <!-- <p> -->
        <input type="button" onClick="formSubmit(this.parentNode)" value="Submit" />
        <input type="button" onClick="google.script.host.close()" value="Cancle" />
    </form>
</body>
<script type="text/javascript">
    function formSubmit(e) {
        google.script.run.sendEmail(e);
    }
</script>

结果:

GAS sendEmail(e)

e 是以下对象。

{
  "subject": "sample subject",
  "body": "sample message"
}

如果我误解了你的问题,请告诉我。我想修改一下。