Gmail 中的自动回复,为什么收到新信件时会出现错误?
Auto reply in Gmail, Why does an error come out when a new letter arrives?
下午好,我在公开场合发现了这个脚本并针对我的任务对其进行了优化,但由于某种原因它不响应传入的信件。有 1 分钟的触发器,但是当收到一封来信时,我收到一个错误 TypeError: Cannot read property 'indexOf' of null in Line 29
我不明白问题出在哪里,我做错了什么?
我很乐意提供任何帮助
function autoReply() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var answer = ss.getRange("A2").getValue();
var fileattach = ss.getRange("B2").getValue();
var mimetype = ss.getRange("C2").getValue();
var interval = 1;
var date = new Date();
var day = date.getDay();
var daysOff = [1,2,3,4,5,6,0];
if (daysOff.indexOf(day) > -1){
var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
var threads = GmailApp.search('is:inbox after:' + timeFrom);
for (var i = 0; i < threads.length; i++) {
if (threads[i].isUnread()){
var sender=threads[i].getMessages()[0].getFrom();
if(PropertiesService.getScriptProperties().getKeys().length==0){
PropertiesService.getScriptProperties().setProperty('from', '');
}
var scriptProperties = PropertiesService.getScriptProperties().getProperty('fromArray');
var attach = DriveApp.getFilesByName(fileattach).next();
if(scriptProperties.indexOf(sender)==-1){
threads[i].reply(answer,{
attachments:[attach.getAs(mimetype)]
});
threads[i].markRead();
scriptProperties=scriptProperties+sender;
PropertiesService.getScriptProperties().setProperty('from', scriptProperties);
}
}
}
}
您收到的 TypeError: Cannot read property 'indexOf' of null in Line 29
错误消息是由于您正在尝试调用 null
对象的 indexOf
方法。
更具体地说,您的错误来自此处的这一行
var scriptProperties = PropertiesService.getScriptProperties().getProperty('fromArray');
并且当您调用 scriptProperties.indexOf
时,因为 scriptProperties
在这种情况下是 null
。
下午好,我在公开场合发现了这个脚本并针对我的任务对其进行了优化,但由于某种原因它不响应传入的信件。有 1 分钟的触发器,但是当收到一封来信时,我收到一个错误 TypeError: Cannot read property 'indexOf' of null in Line 29
我不明白问题出在哪里,我做错了什么?
我很乐意提供任何帮助
function autoReply() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var answer = ss.getRange("A2").getValue();
var fileattach = ss.getRange("B2").getValue();
var mimetype = ss.getRange("C2").getValue();
var interval = 1;
var date = new Date();
var day = date.getDay();
var daysOff = [1,2,3,4,5,6,0];
if (daysOff.indexOf(day) > -1){
var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
var threads = GmailApp.search('is:inbox after:' + timeFrom);
for (var i = 0; i < threads.length; i++) {
if (threads[i].isUnread()){
var sender=threads[i].getMessages()[0].getFrom();
if(PropertiesService.getScriptProperties().getKeys().length==0){
PropertiesService.getScriptProperties().setProperty('from', '');
}
var scriptProperties = PropertiesService.getScriptProperties().getProperty('fromArray');
var attach = DriveApp.getFilesByName(fileattach).next();
if(scriptProperties.indexOf(sender)==-1){
threads[i].reply(answer,{
attachments:[attach.getAs(mimetype)]
});
threads[i].markRead();
scriptProperties=scriptProperties+sender;
PropertiesService.getScriptProperties().setProperty('from', scriptProperties);
}
}
}
}
您收到的 TypeError: Cannot read property 'indexOf' of null in Line 29
错误消息是由于您正在尝试调用 null
对象的 indexOf
方法。
更具体地说,您的错误来自此处的这一行
var scriptProperties = PropertiesService.getScriptProperties().getProperty('fromArray');
并且当您调用 scriptProperties.indexOf
时,因为 scriptProperties
在这种情况下是 null
。