-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemail-with-inline-images.gs
35 lines (34 loc) · 1.08 KB
/
email-with-inline-images.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Sends emails with data from the current spreadsheet with inline images
*/
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = <start row number>; // First row of data to process
var numRows = <number of rows to process>; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 6);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
var posterUrl = "<url for the inline image>";
var posterName = UrlFetchApp
.fetch(posterUrl)
.getBlob()
.setName("posterName");
for (var i in data) {
var row = data[i];
var emailAddress = row[1];
var name = row[2]
var message = "<email body>"
var subject = "<email subject> <img src='cid:posterName'>";
MailApp.sendEmail({
to: emailAddress,
subject: subject,
htmlBody: message,
inlineImages:
{
posterName: posterName
},
cc: "<comma seperated emails to CC>"
});
}
}