Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Send HTML email from Google Apps Script. Full article here: http://blog.gsmart.in/google-apps-script-send-html-email
function onOpen()
{
var ui = SpreadsheetApp.getUi();
ui.createMenu('Process')
.addItem('Approve', 'doApprove')
.addToUi();
}
function doApprove()
{
var cell = SpreadsheetApp.getActiveSheet().getActiveCell();
var row = cell.getRow();
var candidate = getCandidateFromRow(row);
var ui = SpreadsheetApp.getUi();
var response = ui.alert('Approve '+candidate.name+'?', ui.ButtonSet.YES_NO);
if(response == ui.Button.YES)
{
handleApproval(row, candidate);
}
}
function getCandidateFromRow(row)
{
var values = SpreadsheetApp.getActiveSheet().getRange(row, 1,row,3).getValues();
var rec = values[0];
var candidate =
{
first_name: rec[0],
last_name : rec[1],
email: rec[2]
};
candidate.name = candidate.first_name+' '+candidate.last_name;
return candidate;
}
function handleApproval(row, candidate)
{
var templ = HtmlService
.createTemplateFromFile('candidate-email');
templ.candidate = candidate;
var message = templ.evaluate().getContent();
MailApp.sendEmail({
to: candidate.email,
subject: "Your application is approved!",
htmlBody: message
});
SpreadsheetApp.getActiveSheet().getRange(row, 4).setValue('approved');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.