我的脚本一直运行到大约一个月之前。没有错误只是停止了。
我试图在其他人的帮助下重写脚本,但仍然没有......
脚本附加到Google表单响应电子表格。提交表单时,应该发送2封电子邮件。一个是提交者,另一个是收件人。
这是我所在的地方。仍然没有错误..至少没有我知道的。
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();
}
答案 0 :(得分:0)
由于您的SendGoogleForm()
功能作为onFormSubmit
触发器运行,因此代码中的任何错误都会通过Google Apps脚本的自动电子邮件报告给您。您是否已检查脚本所有者的收件箱中是否有#34; Google Apps脚本失败摘要&#34;来自apps-scripts-notifications@google.com
的消息?
您也可以尝试使用MailApp.sendEmail()
代替GmailApp.sendEmail()
。也许它会更可靠地运作?