You can do this by following the below steps,
Uploading the 10 attachments on one google drive folder
On your google sheet add the below script to get the file id
function listFilesInFolder() {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("FileID").activate(); //The name of the google sheet is FileID in my case
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow(["File Name", "File-Id"]);
//change the folder ID below to reflect your folder's ID (look in the URL when you're in your folder)
var folder = DriveApp.getFolderById("*[Enter Folder ID here]*");
var contents = folder.getFiles();
var cnt = 0;
var file;
while (contents.hasNext()) {
var file = contents.next();
cnt++;
data = [
file.getName(),
file.getId(),
];
sheet.appendRow(data);
}
}
- Build a simple script to send emails and have your 10 emails on one column and all the File IDs generated from the above code on the next column. Below is a sample script to send emails from spreadsheets,
function sendEmails() {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Emails").activate(); // Emails is the sheet which has the email and File ID columns
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
var templateText = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(1, 1).getValue(); // Template is the sheet which has my email body
for (var i = 2;i<=lr;i++){
var currentEmail = ss.getRange(i, 1).getValue(); //Email IDs are on the first column for me
var currentAttachment = ss.getRange(i, 2).getValue(); //Assuming your File IDs are on the second column
var waiver = DriveApp.getFileById(currentAttachment);
var liabilityWaiver = waiver.getAs(MimeType.PDF);
MailApp.sendEmail(currentEmail, subjectLine, messageBody, {attachments:[liabilityWaiver],
cc:'abc@abc.com'}); // the cc is in case you want to CC someone else on the email
I hope this helps!