Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

How can you use a Gmail script to attach more than one image at a time?

$
0
0

I'm trying to set up a Google Sheet with some data to email images. I have the code I found online working below to send a single image attachment but I would like to send more than one image at a time if it is possible. How could I change the code below to work with multiple images? I'm totally new to this and like I said just found this code online. I have no idea what I'm doing and surprised myself getting this part to work. Any help getting multiple images to work?

 function emailImage(){  var EMAIL_SENT = "EMAIL_SENT";   var sheet = SpreadsheetApp.getActiveSheet();    var startRow = 2;    var numRows = sheet.getLastRow();   // Fetch the range of cells   var dataRange = sheet.getRange(startRow, 1, numRows, 5)     var data = dataRange.getValues();   for (var i = 0; i < data.length; ++i) {    var row = data[i];    var emailAddress = row[0];  // First column    var subject = row[1];       // Second column    var message = row[2];       // Third column    var image = UrlFetchApp.fetch(row[3]).getBlob();   // Fourth column    var emailSent = row[4];     // Fifth column    if (emailSent != EMAIL_SENT) {  // Prevents sending duplicates      MailApp.sendEmail(emailAddress, subject, message, {attachments: [image]});      sheet.getRange(startRow + i, 5).setValue(EMAIL_SENT);      // Make sure the cell is updated right away in case the script is interrupted      SpreadsheetApp.flush();    }  }}

Viewing all articles
Browse latest Browse all 9782

Trending Articles