Skip to content

Instantly share code, notes, and snippets.

@ayuthmang
Last active August 11, 2017 06:30
Show Gist options
  • Save ayuthmang/302a7f9fa2e838c85bdbab88ee4baffd to your computer and use it in GitHub Desktop.
Save ayuthmang/302a7f9fa2e838c85bdbab88ee4baffd to your computer and use it in GitHub Desktop.
Send emails using Google Script part 2
var subject_skeleton = "อีเมล์ยืนยันสำหรับสั่งซื้อเสื้อออนไลน์";
var content_skeleton = "สวัสดีครับคุณ %s \n" +
"\n"+
"คุณได้ทำการสั่งไซส์เสื้อไว้เป็นไซส์ %s\n" +
"หากไม่ใช่ไซส์คุณสามารถติดต่อกลับได้ที่\n" +
"099-999-9999 หรืออีเมล์ [email protected]\n" +
"\n" +
"ขอขอบพระคุณที่ไว้วางใจเรา";
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 4; // Number of rows to process
// Fetch the range of cells A2:D5
var dataRange = sheet.getRange(startRow, 1, numRows, 4);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var timeStamp = row[0]; // First column
var name = row[1]; // Second column
var email = row[2]; // Third column
var shirtSize = row[3]; // Fourth column
var content = Utilities.formatString(content_skeleton, name, shirtSize);
MailApp.sendEmail(email, subject_skeleton, content);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment