title: Google spreadsheet loop for send email with PDF not working
body: <p>I have google spreadsheet of invoice, where i have used vlookup formula to take data from other (data) sheet. Only I need to enter row number in invoice sheet. So I created loop script where auto row number from data sheet will enter in invoice sheet and send email with PDF attachment. When run that script row Number of each row enter correctly but the email will not go. </p>
  
  <pre><code>function SendInvoiceNew4() {
    var sheet = SpreadsheetApp.getActiveSheet();
  
  // Loop from CELL Number Value to CELL Number Value EQUAL
    for(i=sheet.getRange("H11").getValue();i&lt;=sheet.getRange("I11").getValue();i++) // *************** Enter Start Invoice Serial No Cell Reference &amp; Last Serial No Cell is Auto
    sheet.getRange("H11").setValue(i); //Auto Enter Next Loop Serail Number
  
    var InvDate = Utilities.formatDate(new sheet.getRange("H13").getValue(), "GMT+1", "MMM-yyyy") //Set invoice Date Format = MONTH &amp; YEAR
    var emailTo = sheet.getRange("B12").getValue(); //Get Email Address from Data
    var message = 'Dear' + "\n\n" + 'See attached your attached invoice in PDF format.' + "\n\n" + 'Thanking you' + "\n" + 'www.xyz.in' + "\n" + '[DO NOT REPLY to this Email.]'; //Enter Custom Messagen ************************************************** Message Body
    var subject = 'Invoice for Month ' + InvDate;  // ************* Enter Cell Reference for Date of Invoice for Subject
  
  // Convert Invoice Sheet to PDF
    var originalSpreadsheet = SpreadsheetApp.getActive(); // Set original invoice sheet
    var pdf = DriveApp.getFileById(originalSpreadsheet.getId()).getAs('application/pdf').getBytes(); // Convert PDF file
    var attach = {fileName:'Invoice',content:pdf, mimeType:'application/pdf'}; //Set File Name
  
  // Send Email with attached PDF file   
    //MailApp.sendEmail(emailTo, subject, message, {attachments:[attach]});
    MailApp.sendEmail(emailTo, subject, message);
    SpreadsheetApp.flush(); // Make sure the cell is updated right away in case the script is interrupted
  
  }
  </code></pre>