title: Google App Script : Error when attaching multiple images (Unexpected error while getting the method or property getFileById on object DriveApp)
body: <p>I am writing an automated script to send mails from my Google sheets and I want to attach multiple Images. With only one image everything works perfectly fine but when I want to attach two or more, it gives me this Error message:</p>
  <p>Exception: Unexpected error while getting the method or property getFileById on object DriveApp.</p>
  <p>This is my code right now:</p>
  <pre><code>function sendEmails() {
    var sheet = SpreadsheetApp.getActiveSheet();
    var startRow = 1; // First row of data to process
    var numRows = 3; // Number of rows to process
    // Fetch the range of cells A2:B3
    var dataRange = sheet.getRange(startRow, 1, numRows, 5);
    // Fetch values for each row in the Range.
    var data = dataRange.getValues();
    for (var i in data) {
      var row = data[i];
      var emailAddress = row[0]; // First column
      var message = row[1]; // Second column
      var image = DriveApp.getFileById(row[2]).getBlob();
      var image2 = DriveApp.getFileById(row[3]).getBlob();
      var subject = 'TAYDO 2021 Certificate';
    }
  
    MailApp.sendEmail({
      to:emailAddress, 
      subject:subject,   
      body:message,  
      attachments: [image.next(),image2]
    });
  }
  </code></pre>
  <p>The App script has all permissions needed to run this script, and sheets, drive and everything is under the same Google Acc.
  Can anyone help? Thanks in advance!</p>