Google apps script GmailApp.sendmail已停止工作
大约一个月前,我的脚本还在运行。。没有错误,只是简单地停止了 在别人的帮助下,我试图重写剧本,但还是一无所获 该脚本附加到Google表单响应电子表格。提交表格时,应发送两封电子邮件。一个给提交人,一个给接收人 这就是我现在的处境。仍然没有错误。。至少据我所知没有Google apps script GmailApp.sendmail已停止工作,google-apps-script,google-sheets,Google Apps Script,Google Sheets,大约一个月前,我的脚本还在运行。。没有错误,只是简单地停止了 在别人的帮助下,我试图重写剧本,但还是一无所获 该脚本附加到Google表单响应电子表格。提交表格时,应发送两封电子邮件。一个给提交人,一个给接收人 这就是我现在的处境。仍然没有错误。。至少据我所知没有 function getResponseURL(timestamp) { var id = SpreadsheetApp.getActive().getFormUrl().match(/[\_\-\w]{25,}/); var for
function getResponseURL(timestamp) {
var id = SpreadsheetApp.getActive().getFormUrl().match(/[\_\-\w]{25,}/);
var form = FormApp.openById(id);
var resp = form.getResponses(new Date(timestamp.getTime() - 1000*5));
if (resp.length) return resp[0].getEditResponseUrl(); else return "";
}
function SendGoogleForm(e) {
var val = {
/*
Enter column header for recipient address
For an example
'subject': 'Email'
*/
'recipient': 'Email',
/*
Enter your email alias
*/
'alias': 'email@themarcjosephband.ca',
/*
Receiver's email for the notifications:
*/
'to': 'info@themarcjosephband.ca',
/*
ReplyTo email for the receiver's notifications:
*/
'replyto' : 'info@themarcjosephband.ca',
/*
1. the subject includes a row number and the person's name automatically - just want to fill in the text afterwards
Change the 'subject' value below.
For an example
'subject': 'test'
OR
'subject': 'the text afterwards'
*/
'subject': 'Quote Request',
'subject2': 'Quote Request',
/*
2. the body of course includes the form fields that were filled in, I just want to add text prior to that.
Change the 'text' value below.
For an example
'text': 'test'
OR
'text': 'add text prior to that'
*/
'text': 'The following quote request has been submitted.'
}
var recipient = "";
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var subject = "[#" + s.getLastRow() + "] " + e.namedValues["Name"].toString() + " " + val.subject;
var body, message = [['','']];
for(var i in headers) {
var col = headers[i];
if ( e.namedValues[col] && (e.namedValues[col].toString() !== "") && (col !== "Timestamp") && col !== "What is the color of oranges?" ) {
message.push([col, e.namedValues[col].toString()]);
if (col === val.recipient) {
recipient = e.namedValues[col].toString();
}
}
}
var textBody = "", htmlBody = "";
for (var i=0; i<message.length; i++) {
htmlBody += "<tr><td><strong>" + message[i][0] + '</strong></td><td>'+ message[i][1] + "</td></tr>";
textBody += message[i][0] + " :: " + message[i][1] + "\n\n";
}
htmlBody = val.text + "<br /><br /><table border='0' cellspacing='0' cellpadding='2'>" + htmlBody + "</table>";
textBody = val.text + "\n\n" + textBody;
var responseURL = getResponseURL(new Date(e.namedValues["Timestamp"].toString()));
/*
3. the body also includes a line with a link to edit the response at the end.
It's below
*/
if (responseURL !== "") {
htmlBody = htmlBody + "<br><br>" + "You can edit the response by <a href='" + responseURL + "'>clicking here</a>.";
textBody = textBody + "\n\n" + "Click the link below to edit the response:\n" + responseURL;
}
GmailApp.sendEmail ( val.to, subject, textBody, {
htmlBody: htmlBody, replyTo: recipient, from: val.alias } );
GmailApp.sendEmail ( recipient, val.subject2, textBody, {
htmlBody: htmlBody, replyTo: val.replyto, from: val.alias } );
}
function Authorize() {
Browser.msgBox("Script authorized.");
}
function InitializeTriggers() {
Reset(true);
ScriptApp.newTrigger("SendGoogleForm")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
}
函数getResponseURL(时间戳){
var id=SpreadsheetApp.getActive().getFormUrl().match(/[\\-\w]{25,}/);
var form=FormApp.openById(id);
var resp=form.getResponses(新日期(timestamp.getTime()-1000*5));
if(resp.length)返回resp[0]。getEditResponseUrl();else返回“”;
}
函数SendGoogleForm(e){
var val={
/*
输入收件人地址的列标题
例如
“主题”:“电子邮件”
*/
“收件人”:“电子邮件”,
/*
输入您的电子邮件别名
*/
'别名':'email@themarcjosephband.ca',
/*
收件人的通知电子邮件:
*/
“到”:info@themarcjosephband.ca',
/*
回复收件人通知的电子邮件:
*/
“回复:”info@themarcjosephband.ca',
/*
1.主题自动包含行号和人名-只需在之后填写文本
更改下面的“主题”值。
例如
“主题”:“测试”
或
“主题”:“之后的文本”
*/
“主题”:“报价请求”,
“主题2”:“报价请求”,
/*
2.正文当然包括填写的表单字段,我只想在此之前添加文本。
更改下面的“文本”值。
例如
“文本”:“测试”
或
“文本”:“在此之前添加文本”
*/
“text”:“已提交以下报价请求。”
}
var=”;
var s=SpreadsheetApp.getActiveSheet();
var headers=s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var subject=“[#”+s.getLastRow()+“]”+e.namedValues[“Name”].toString()+”+val.subject;
变量主体,消息=[['',]];
for(标题中的变量i){
var col=标题[i];
如果(e.namedValues[col]&&(e.namedValues[col].toString()!==“”)&&&(col!==“Timestamp”)&&col!==“橙子是什么颜色的?”){
message.push([col,e.namedvalue[col].toString()]);
if(col==val.recipient){
recipient=e.namedValues[col].toString();
}
}
}
var textBody=“”,htmlBody=“”;
对于(var i=0;i,因为您的
SendGoogleForm()
函数正在作为onFormSubmit
触发器运行,因此代码中的任何错误都将通过来自Google Apps脚本的自动电子邮件报告给您。您是否查看了脚本所有者的收件箱中的“Google Apps脚本失败摘要”来自应用程序脚本的消息-notifications@google.com
您也可以尝试使用
MailApp.sendmail()
而不是GmailApp.sendmail()
。也许它会工作得更可靠?因为您的SendGoogleForm()
功能正在作为onFormSubmit
触发器运行,代码中的任何错误都将通过来自Google Apps脚本的自动电子邮件报告给您。您是否查看了来自Apps脚本的脚本所有者收件箱中的“Google Apps脚本失败摘要”消息-notifications@google.com
您还可以尝试使用
MailApp.sendmail()
而不是GmailApp.sendmail()
。也许它会工作得更可靠?当脚本突然停止时,没有发送任何通知。这就是我说没有错误的意思。在测试这些重新写入后,这些是昨晚发送给我的错误摘要:错误消息计数无效参数:email@themarcjosephband.ca(第133行,文件“代码”)ReferenceError:“getResponseURL”未定义。(第113行,文件“代码”)详细信息:SendGoogleForm无效参数:email@themarcjosephband.ca(第133行,文件“代码”)formSubmit SendGoogleForm ReferenceError:“getResponseURL”未定义。(第113行,文件“代码”)FormSubmit当脚本突然停止时,没有发送任何通知。这就是我所说的“无错误”的意思。在测试这些重新写入后,这些是昨晚发送给我的错误摘要:错误消息计数无效参数:email@themarcjosephband.ca(第133行,文件“代码”)引用错误:“getResponseURL”未定义。(第113行,文件“代码”)详细信息:SendGoogleForm无效参数:email@themarcjosephband.ca(第133行,文件“代码”)formSubmit SendGoogleForm ReferenceError:“getResponseURL”未定义。(第113行,文件“代码”)formSubmit