Google脚本在Object中找不到函数LastIndexOf

时间:2015-02-12 10:14:01

标签: javascript google-apps-script

我收到此主题中的错误:

var startPos = msgBody.LastIndexOf("To:");

在此功能中:

function Scanning_Gmail_Mailbox() {    

  if (!UserProperties.getProperty("start")) {
    UserProperties.setProperty("start", "0");    
  }

  var start   = parseInt(UserProperties.getProperty("start"));
  var ss = SpreadsheetApp.openById("1yts3_XhVD1cyAHmKa_R8QYDPpdgVdBjbSq5OMzIoI4o");
  var sheet = ss.getSheetByName("EmailAddresses");
  var row     = 1;

  sheet.getRange(row,1).setValue("Email Addresses");
  row++;

  for (;;) {


  // Find all Gmail messages that have been rejected
    var threads = GmailApp.search('From:mailer-daemon@googlemail.com', start, 500);

  if (threads.length == 0) {
    ss.toast("Processed " + start + " messages.", "Scanning Done", -1);
    return;
  }

  for (var i=0; i<threads.length; i++) {

    var messages = threads[i].getMessages();
    UserProperties.setProperty("start", ++start);

    for (var m=0; m<messages.length; m++) {     

      var msgBody = messages[m].getPlainBody();
      msgBody.toString;

      var startPos = msgBody.LastIndexOf("To:");

      var strEmailAddress = msgBody.slice(msgBody.startPos+4,200);
      strEmailAddress = strEmailAddress.slice(1,msgBody.IndexOf(" ")-1);
      sheet.getRange(row,1).setValue(strEmailAddress);
      row++;

    }            
  }    
  }
}

1 个答案:

答案 0 :(得分:0)

方法是lastIndexOf(注意l是小例)

var startPos = msgBody.lastIndexOf("To:");