Last active
May 18, 2017 21:15
-
-
Save alaq/e8f0a9bc633c252140bdff477f002d30 to your computer and use it in GitHub Desktop.
Simple mass emailer from a Google spreadsheet. In the first sheet B2 is the subject, B3 is the body, B4 is the hml body.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendEmails() { | |
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets(); | |
var subject = sheets[0].getRange("B2").getValue(); | |
var textBody = sheets[0].getRange("B3").getValue(); | |
var logoBlob = UrlFetchApp.fetch("http://i62.tinypic.com/6emz6f.png").getBlob().setName("logoBlob"); // Replace here with your own image | |
var inlineBody = sheets[0].getRange("B4").getValue(); | |
var dataRange = sheets[1].getDataRange(); | |
var data = dataRange.getValues(); | |
for (var i = 0; i < data.length; i++) { | |
(function(val) { | |
var row = data[i]; | |
var emailAddress = row[0]; | |
Logger.log(emailAddress); | |
MailApp.sendEmail(emailAddress, subject, textBody, | |
{ htmlBody: inlineBody, | |
inlineImages: | |
{ | |
logo: logoBlob, | |
} | |
}); | |
})(i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment