Created
August 16, 2015 21:56
-
-
Save n8henrie/eb13c9ff556ba02c91f3 to your computer and use it in GitHub Desktop.
Send the response content from a simple Google Form to an email address.
This file contains hidden or 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
// google_form_to_email.gs | |
// Google App Script to take response content from a Google Form and send it to an email address. | |
// Make a publically accessible Google Form, share as a "secret link," and if desired shorten | |
// with a custom Bitly link (assuming you have a free domain sitting around). | |
// Installation: From the *form* (not the spreadsheet with the responses), copy this into | |
// Tools -> Script Editor. In Script Editor, set up your trigger to be "on form submit." | |
// Customize the values in SETUP, and customize the message if desired. | |
// The script will loop over all the rows in the spreadsheet except the header row, email | |
// the content to the recipient address, then delete that row. | |
/////////////////////////////// | |
// SETUP | |
// | |
// Destination email address | |
var recipient = "[email protected]"; | |
// | |
// With the *spreadsheet* open (not the form), the ID is the part between /d/ and /edit#, | |
// e.g. "i3ij2iejifjx98jeiwejf" in | |
// https://docs.google.com/spreadsheets/d/i3ij2iejifjx98jeiwejf/edit#gid=0 | |
var sheetId = "i3ij2iejifjx98jeiwejf" | |
// | |
// Resources -> Current Project's Triggers | |
// emailNote | from spreadsheet | on form submit | |
/////////////////////////////// | |
function emailNote() { | |
var ss = SpreadsheetApp.openById(sheetId); | |
var sheet = ss.getSheets()[0]; | |
var lastRow = sheet.getLastRow(); | |
for (var i = 2; i <= lastRow; i++) { | |
var range = sheet.getRange("A2:B2"); | |
var row = range.getValues()[0]; | |
// Number-only rows fail the `slice` if not casted to string | |
var timestamp = row[0].toString(); | |
var data = row[1].toString(); | |
// for debug | |
// Logger.log("Timestamp: " + timestamp); | |
// Logger.log("Data: " + data); | |
var url = "https://docs.google.com/spreadsheets/d/" + sheetId + "/edit"; | |
// Preview task content in subject | |
var subject = "Task from Google Form: " + data.slice(0,30); | |
// Include timestamp and link to spreadsheet in message body | |
var message = "Task from Google Form, added " + timestamp + | |
"\n" + url + "\n\n" + data; | |
// for debug | |
// Logger.log(subject); | |
// Logger.log(message); | |
MailApp.sendEmail(recipient, subject, message); | |
sheet.deleteRow(2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment