title: Google Script sending automated email on delay
body: <p>I’m having a particular issuing when using Google script editor. </p>
  
  <p>I having a spreadsheet that once a form is submitted, it pulls the name from the form and pulls their email. Then sends them an email. </p>
  
  <p>For some reason, it’s sending the email, heavily delayed at about an hour. There’s only been two changes since it’s been working. 1. For some reason the spreadsheet keeps reverting to Central Time instead of Eastern (messing up the time stamps) 2. I added array formulas at the top to solve for the form inputting new rows. </p>
  
  <p>I can paste code here in a bit, but was hoping anyone had some insight. </p>
  
  <p>I’m using GmailApp.sendemail</p>
  
  <p>Here is the code </p>
  
  <pre><code>function onEdit(e) {
      var range = e.range;
      var row = range.getRow();
    //This is the section you change to line up the rows with the values you are trying to pull
    //The var defines the variable and the blue text is naming the return value
      var emailToColumn = 2; // B
      var answerColumn = 4; //D
      var statusColumn = 6; // F
      var questionColumn = 3; //C
      var emailStampColumn = 7; //G
      var sessionColumn = 10;
      var assignedToColumn = 5; //E
    //This tells the code which row to check and pull values from
      var stampCheck =  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 3").getRange(row, emailStampColumn).getValue();
      var answerValue = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 3").getRange(row, answerColumn).getValue();
      var emailToValue = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 3").getRange(row, emailToColumn).getValue();
      var questionValue = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 3").getRange(row, questionColumn).getValue();
      var statusAnswer = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 3").getRange(row, statusColumn).getValue();
      var sessionValue = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 3").getRange(row, sessionColumn).getValue();
      var assignValue = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 3").getRange(row, assignedToColumn).getValue();
  
  
       //This is a check to make sure email is answered
      if ( statusAnswer == 'Assigned' &amp;&amp; stampCheck.length == 0 ) {
       var emailAssign = assignValue;  
        //This is the actual email text
          var subject = "You Have Been Assigned A Question";
    var htmlStr = "";
    htmlStr+= "&lt;p&gt;Hello,&lt;/p&gt;";
    htmlStr+= "&lt;p&gt;This is to inform that you have been asked a question&lt;/p&gt;";
    htmlStr+= "&lt;p&gt;&lt;b&gt;Navigate to this link &lt;/b&gt;&lt;/p&gt;";
    htmlStr+= "&lt;p&gt;&lt;b&gt;Your question is in column C:&lt;/b&gt;&lt;/p&gt;"; 
    htmlStr+= "&lt;p&gt;" + questionValue + "&lt;/p&gt;";
    htmlStr+= "&lt;p&gt;Thank you!&lt;/p&gt;";
  
    GmailApp.sendEmail(emailAssign, subject, "", {
      htmlBody: htmlStr})
  
  
      //var statusColumn = range.getColumn(); //5 
      //var answerColumn = 3;
      //if ( range.getColumn() === answerColumn ) {
          //if ( e.value.length &gt; 0 ) {
              //if ( SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses").getRange(range.getRow(), range.getColumn()) ) {
  
              //}
          //}
      //}
    //var progress = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses").getRange(range.getRow(), range.getColumn() + 2).getValue();
  //   SpreadsheetApp.getUi().alert('Column changed FROM   ' + e.oldValue + '   TO   ' + e.value + '   AT   ' + range.getA1Notation() + '\t' + answerValue + '   ' + statusAnswer);
     //SpreadsheetApp.getUi().alert(answerValue.length + '   ' + statusAnswer);
      }
  
        //THIS IS WHERE SECOND PORTION OF CODE BEGINS
  
     //This is a check to make sure email is answered
      if ( answerValue.length &gt; 0 &amp;&amp; statusAnswer == 'Completed' &amp;&amp; stampCheck.length == 0 ) {
       var emailTo = emailToValue;  
        //This is the actual email text
    var subject = "Territory Tech Forum Answer";
    var htmlStr = "";
    htmlStr+= "&lt;p&gt;Hello,&lt;/p&gt;";
    htmlStr+= "&lt;p&gt;This is line one of the email&lt;/p&gt;";
    htmlStr+= "&lt;p&gt;&lt;b&gt;This is line two - it is bolded because it has a bold tag surrounding it&lt;/b&gt;&lt;/p&gt;";
    htmlStr+= "&lt;p&gt;&lt;b&gt;Your question:&lt;/b&gt;&lt;/p&gt;"; 
    htmlStr+= "&lt;p&gt;" + questionValue + "&lt;/p&gt;";
    htmlStr+= "&lt;p&gt;&lt;b&gt;The answer to your question:&lt;/b&gt;&lt;/p&gt;";
    htmlStr+= "&lt;p&gt;" + answerValue + "&lt;/p&gt;";
    htmlStr+= "&lt;p&gt;Thank you!&lt;/p&gt;";
  
    GmailApp.sendEmail(emailTo, subject, "", {
      htmlBody: htmlStr})
  
    var stampValue = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 2").getRange(row, emailStampColumn).setValue(new Date()).setNumberFormat("MM/dd/yyyy hh:mm");
      //var statusColumn = range.getColumn(); //5 
      //var answerColumn = 3;
      //if ( range.getColumn() === answerColumn ) {
          //if ( e.value.length &gt; 0 ) {
              //if ( SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses").getRange(range.getRow(), range.getColumn()) ) {
  
              //}
          //}
      //}
    //var progress = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses").getRange(range.getRow(), range.getColumn() + 2).getValue();
  //   SpreadsheetApp.getUi().alert('Column changed FROM   ' + e.oldValue + '   TO   ' + e.value + '   AT   ' + range.getA1Notation() + '\t' + answerValue + '   ' + statusAnswer);
     //SpreadsheetApp.getUi().alert(answerValue.length + '   ' + statusAnswer);
  
  }
  }
  </code></pre>