Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablojimeno/5ec99a3094420b56e69da9517ab6f147 to your computer and use it in GitHub Desktop.
Save pablojimeno/5ec99a3094420b56e69da9517ab6f147 to your computer and use it in GitHub Desktop.
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