title: Error: "Failed to send email: no recipient"
body: <p>I'm getting the error when I run the code below:</p>
  
  <blockquote>
    <p>Failed to send email: no recipient</p>
  </blockquote>
  
  <p>This is being run off or a google spreadsheet.  I'm assuming that it's going to look for an email address in the email address column and after it reads the last one, it goes for the next blank cell and doesn't see anything, then giving an error. </p>
  
  <p>If this is the case, how can I get it to stop looking for email addresses when it goes to the last one in a column?</p>
  
  <p>The error is in line 18: <code>MailApp.sendEmail(emailAddress, subject, message);</code></p>
  
  <pre><code>    var EMAIL_SENT = "EMAIL_SENT";
  
  function sendEmails2() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheets = ss.getSheets();
    var startRow = 2;  
    var numRows = 1000;
    var sheet = ss.getSheetByName ('Administrators')
    var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
    var data = dataRange.getValues();
    for (var i = 0; i &lt; data.length; ++i) {
      var row = data[i];
      var emailAddress = row[1]; 
      var message = row[28];       
      var emailSent = row[29]; 
      if (emailSent != EMAIL_SENT) {  
        var subject = "Tuition Reimbursement Status";
        MailApp.sendEmail(emailAddress, subject, message);
        sheet.getRange(startRow + i, 30).setValue(EMAIL_SENT);
  
  
       var sheet = ss.getSheetByName ('Teachers')
       var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
       var data = dataRange.getValues();
       for (var i = 0; i &lt; data.length; ++i) {
       var row = data[i];
       var emailAddress = row[1]; 
       var message = row[28];       
       var emailSent = row[29]; 
       if (emailSent != EMAIL_SENT) {  
         var subject = "Tuition Reimbursement Status";
         MailApp.sendEmail(emailAddress, subject, message);
         sheet.getRange(startRow + i, 30).setValue(EMAIL_SENT);
  
  
       var sheet = ss.getSheetByName ('Support Staff')
       var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
       var data = dataRange.getValues();
       for (var i = 0; i &lt; data.length; ++i) {
       var row = data[i];
       var emailAddress = row[1]; 
       var message = row[28];       
       var emailSent = row[29]; 
       if (emailSent != EMAIL_SENT) {  
         var subject = "Tuition Reimbursement Status";
         MailApp.sendEmail(emailAddress, subject, message);
         sheet.getRange(startRow + i, 30).setValue(EMAIL_SENT);
  
  
  
        SpreadsheetApp.flush();
        }
       }
      }
     }
    }
   }
  }
  </code></pre>