使用Google脚本在不使用服务器的情况下发送电子邮件:无法打开文件错误 [英] Send email without server using google script: unable to open file error
问题描述
我想使用Google脚本将电子邮件发送到位置 target@example.com .我正在关注-
当我单击最新代码上的测试" Web应用程序时,会看到相同的屏幕.
我发现的内容-
我需要在表单内的html标记中添加一些东西作为名称"属性,但不清楚要添加什么.
在设置此功能时我哪里出错了?
好的,我想我已经解决了您的问题.
似乎有两个问题:
- 您似乎已经使用两个gmail帐户登录了:这就是/u/1附加到脚本地址的原因(我们不需要它,可能是一个错误).因此, https://script.google.com/macros/u/1/s/AKfycbwYbJ5WvIRmizYMr8MMtNVdIodpdYcJHz4DuO97Oxnuw4lnu3k/exec 变成当前项目"的触发器(或者我们也可以使用时钟"按钮).在此处添加触发器.在运行下,选择doPost(),在事件下,从电子表格中选择->然后提交表单.保存.
- 当您访问 https://script.google.com/macros/s//来自浏览器的AKfycbwYbJ5WvIRmizYMr8MMtNVdIodpdYcJHz4DuO97Oxnuw4lnu3k/exec (不带/u/1 :-)),它会给出以下错误:doGet()函数不存在,这是正确的,并且您的网络浏览器发送了GET请求.
- You seemed to be logged in with two gmail account: That is why /u/1 got appended to script address (we don't need it, may be a bug). So, https://script.google.com/macros/u/1/s/AKfycbwYbJ5WvIRmizYMr8MMtNVdIodpdYcJHz4DuO97Oxnuw4lnu3k/exec becomes https://script.google.com/macros/s/AKfycbwYbJ5WvIRmizYMr8MMtNVdIodpdYcJHz4DuO97Oxnuw4lnu3k/exec
- You need to add a trigger to your script. When you hit the url, that trigger will call a particular function of your script. What you need to do is set a trigger that fires doPost() whenever submit is clicked. doPost() sends your email.
- How to add trigger? Go to Edit > Current projects' trigger (or we can use the clock button too). Add your trigger there. Under run, select doPost(), under event select from spreadsheet -> then on form submit. Save it.
- When you access https://script.google.com/macros/s/AKfycbwYbJ5WvIRmizYMr8MMtNVdIodpdYcJHz4DuO97Oxnuw4lnu3k/exec from browser (without /u/1 :-) ) it will give error that doGet() function is not present which is true and your web browser sent a GET request.
I want to send an email to a location target@example.com using google script . I am following this - https://github.com/dwyl/html-form-send-email-via-google-script-without-server to setup the whole functionality in my website.
There is an html form in my website and I want to send email whenever someone clicks on the submit button on my site
here is the html of the form -
<div id="content">
<h1>Contact Us</h1>
<h4>Fill out the form below and a representative will
contact you shortly.</h4>
<form id="gform" method="POST" action="https://script.google.com/macros/u/1/s/AKfycbwYbJ5WvIRmizYMr8MMtNVdIodpdYcJHz4DuO97Oxnuw4lnu3k/exec">
<div class="form-group">
<label for="exampleInputEmail1">Your Name (required)</label>
<input type="text" class="form-control" id="exampleInputEmail1" required>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Your Email (required)</label>
<input type="Email" class="form-control" id="exampleInputPassword1" required>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Subject</label>
<input type="text" class="form-control" id="exampleInputPassword1">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Message</label>
<textarea class="message"></textarea>
</div>
<button type="submit" class="btn btn-default">Submit</button>
Here is the script.gs file -
/******************************************************************************
* This tutorial is based on the work of Martin Hawksey twitter.com/mhawksey *
* But has been simplified and cleaned up to make it more beginner friendly *
* All credit still goes to Martin and any issues/complaints/questions to me. *
******************************************************************************/
var TO_ADDRESS = "target@example.com"; // where to send form data
function doPost(e) {
try {
Logger.log(e); // the Google Script version of console.log see: Class Logger
MailApp.sendEmail(TO_ADDRESS, "Contact Form Submitted",
JSON.stringify(e.parameters));
// return json success results
return ContentService
.createTextOutput(
JSON.stringify({"result":"success",
"data": JSON.stringify(e.parameters) }))
.setMimeType(ContentService.MimeType.JSON);
} catch(error) { // if error return this
Logger.log(error);
return ContentService
.createTextOutput(JSON.stringify({"result":"error", "error": e}))
.setMimeType(ContentService.MimeType.JSON);
}
}
When I click on submit button after filling in the form I get this -
I get the same screen when I click on Test web app on your latest code.
What I've found out -
There is something I need to add to my html tags inside form as "name" attribute but its not very clear what to add.
Where am I going wrong in setting up this feature ?
Okay, I think I have figured out your problem.
There seems to be two problem:
Notes:
这篇关于使用Google脚本在不使用服务器的情况下发送电子邮件:无法打开文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!