简体   繁体   English

google侧边栏和应用脚本发送包含主题和正文的电子邮件

[英]google sidebar & app script sending email composing subject and body

I need help with setting up a google sheets sidebar to accept input for the subject and email body? 我在设置Google表格侧边栏以接受主题和电子邮件正文的输入时需要帮助吗?

I have been able to get one to work but not both. 我已经可以让一个工作,但不能两个都工作。 Code below.... 下面的代码...

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

You want to use the values from textbox and textarea at sendEmail() of GAS side. 您想使用GAS端sendEmail()中textbox和textarea中的值。 If my understanding is correct, how about this modification? 如果我的理解是正确的,那么该修改如何? I think that there are several answers to your situation. 我认为您的情况有几个答案。 So please think of this as one of them. 因此,请将此视为其中之一。

Modification points: 修改要点:

  • There is no </p> for <p> . </p>没有</p> <p>
  • It used this.parentNode for retrieving values. 它使用this.parentNode检索值。

Modified script: 修改后的脚本:

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

Result: 结果:

e of sendEmail(e) at GAS is the following object. esendEmail(e)在GAS是以下目的。

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

If I misunderstand your question, please tell me. 如果我误解了您的问题,请告诉我。 I would like to modify it. 我想修改它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM