The components involved in this workflow are:
- A script to generate and send an email with an HTML form.
- An html template for that email, which allows us to customize the email for each recipient.
- A
doPost()
function to handle responses. The script must be deployed as a Web App. - A spreadsheet to collect responses. The script will be contained in the spreadsheet, and extends the spreadsheet UI with a menu for sending a copy of the survey. (It could be adapted for standalone use, without the UI component.)
Here is an example of such a workflow, conducting a Commuting Survey. Recipients will receive a survey email like this:
Recipients fill out the form right in their email client, if it supports that capability. Responses will be collected in a spreadsheet, like this:
Create the spreadsheet headers yourself, before running the script.
The "Serial Number" column has been added to illustrate a way to correlate responses with particular respondents; note that some entries repeat. When a survey email is generated, it is given a unique serial number, which is then passed back as a hidden value with the responses. We could extend this system to recognize updates from respondents, for instance.
For users without appropriate HTML FORM support in their clients, links are provided in both plain text and html versions of the mail.
To use this survey system as-is:
- Create a new spreadsheet in your Drive account. Add headers for "Timestamp", "Serial Number", "Commuter?", and "Vehicle" in row 1.
- Tools - Script Editor. Copy the
Code.js
content. Copy the ID of your spreadsheet, and update the_spreadsheetId
variable at the top of the file. Save. - File - New HTML file, name the file emailTemplate. Copy the
emailTemplate.html
content. Save. - Publish - Deploy as Web app... Make it accessible by anyone, including anonymous. (In a Google Apps domain, you can restrict it to users in the domain.)
- Authorize the script, by reloading your spreadsheet or running the
onOpen
function in the editor.
Ready to go! You'll find a "Custom Menu" in your spreadsheet, with a "Send Survey" command.
I am also trying something similar to this, sending bulk mails given in a spreadsheet. I want to ask if there is any way to extract email id of receiver from metadata or header and when that user clicks "submit" button, email id will go as parameter to doPost() method and it can be stored in spreadsheet?