title: Fail to Send an email with attachment using Google Apps Script
body: <pre><code>function SendEmails() {
  
  
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Name List").activate();
  
    var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
    var lr = ss.getLastRow(); 
  
    var templateText = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Email Template").getRange(1, 1).getValue();
  
    var quotaLeft = MailApp.getRemainingDailyQuota();
    //Logger.log(quotaLeft);
    if ((lr-1) &gt; quotaLeft){
       Browser.msgBox("You have " + quotaLeft + " left and you're trying  to send " + (lr-1) + "emails. Emails were not sent.");
       } else {
  
    for (var i = 2;i&lt;=lr;i++){
  
         var currentName = ss.getRange(i, 1).getValue();
         var currentAppNo = ss.getRange(i, 2).getValue();
         var currentEmail = ss.getRange(i, 3).getValue();
  
         var messageBody = templateText.replace("{First Name}",currentName).replace("{App No}",currentAppNo);
         var subjectLine = "CONGRATULATION ON YOUR VAL APPROVAL " + currentName
         var attachmentBody = DriveApp.getFilesByName("THE ROOM SCRIPT.pdf");
  
  
        MailApp.sendEmail(currentEmail, subjectLine, messageBody)
  
      } //close for loop
  
            } //close else statement
  }
  </code></pre>
  
  <p>I have a Google Spreadsheet with a list of emails. I want to build a routine that sends email automatically to those email addresses. I also want to attach a PDF to this email. The PDF file is located on my Google Drive.</p>
  
  <p>This does not seem to work</p>