Thursday, December 6, 2012

Email confirmation after sending Google form

Google Apps Script is a scripting language that provides easy ways to automate tasks across Google Drive. 

This tutorial explains a script that sends an email confirmation after submitting the Google Form.

Sending email from GAS is very simple:

function sendEmail() {
    MailApp.sendEmail(“”, “Confirmation”, “Hello customer.”);

Usually there is a need to customize the email body. For example from Google Spreadsheet:

function sendEmail() {
    var message = “Hi ${firstname} ${lastname}, Thank you for buying gun.”
    MailApp.sendEmail( email , “Confirmation”, message);

After submitting Google Form script finds the last row in the spreadsheet and puts value instead of the column name. For example from ${firstname} to John.

When you want to send a comprehensive email, it might be better to use HTML email body.
function sendEmail() {    
  var message = createTemplateFromFile( TEMPLATE_FOR_CUTOMER );
  MailApp.sendEmail( email, “Confirmation”, "", {htmlBody: message});

HTML template for customer

And this is the idea of ​​the script. After submitting Google Form script finds last row from spreadsheet and puts value to html template. HTML template, you can change and expand as your needs. Filled template is used as email body.

The last important task is to set the trigger. From the main menu of Script Editor click to:
Resources > All your triggers

Source code can be downloaded from: Github.



I was inspired by a great book Google Apps Script for Beginners

The book contains:

  • Spreadsheet automation
  • Manipulate Forms
  • Managing Email Account
  • Script in text document
  • Standalone Web application

No comments:

Post a Comment