Skip to content

Instantly share code, notes, and snippets.

@joshpalmeri
Created June 9, 2015 14:20
Show Gist options
  • Save joshpalmeri/7cfe68ca3203b2c3923c to your computer and use it in GitHub Desktop.
Save joshpalmeri/7cfe68ca3203b2c3923c to your computer and use it in GitHub Desktop.
/* Send Confirmation Email with Google Forms */
function Initialize() {
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("SendConfirmationMail")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
}
function SendConfirmationMail(e) {
try {
var ss, cc, sendername, subject, columns, replytoemail, bccemails;
var message, value, textbody, sender, firstname;
var me = Session.getActiveUser().getEmail();
var aliases = GmailApp.getAliases();
// This is your email address and you will be in the CC
//cc = Session.getActiveUser().getEmail();
//cc = '[email protected]';
// This will show up as the sender's name
sendername = "Stony Brook University Alumni Association";
replytoemail = "[email protected]";
//bccemails = "[email protected]";
ss = SpreadsheetApp.getActiveSheet();
columns = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0];
// This is the submitter's email address
sender = e.namedValues["Your Email Address"].toString();
firstname = e.namedValues["Your First Name"].toString();
// Optional but change the following variable
// to have a custom subject for Google Docs emails
subject = "Thank You, " + firstname + ", for Your 40 Under Forty Nomination!";
// This is the body of the auto-reply
message = "Thank you for your nomination for the 2015 Stony Brook University 40 Under 40 Alumni Awards. <br><br>";
message += "All nominations are under review at this time and the recipients will be contacted in Fall 2015. Nominees who are not selected this year will remain in the selection pool for future review, and will continue to be considered in years to come.<br><br>";
message += "For more information, please contact [email protected]. <br><br>";
message += "Sincerely, <br>";
message += "Kristin Matthews, <br>";
message += "Associate Director of Alumni Relations <br>";
message += "(631) 632-6130<br><br><br><br><br><br><br><br><br><br>";
message += "Response Summary<br><br>";
message += "----------------------------------------<br><br>";
// Only include form values that are not blank
for ( var keys in columns ) {
var key = columns[keys];
if ( e.namedValues[key] ) {
message += key + ' :: '+ e.namedValues[key] + "<br />";
}
}
textbody = message.replace("<br>", "\n");
GmailApp.sendEmail(sender, subject, textbody, {cc: cc, name: sendername, replyTo: replytoemail, bcc: bccemails, htmlBody: message});
} catch (e) {
Logger.log(e.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment