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(“customer@gmail.com”, “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.


Trigger
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.

Links


Recommendation

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

Sunday, December 2, 2012

Import Gaelyk project to Eclipse IDE

Gaelyk is a lightweight Groovy toolkit for Google App Engine Java and have a good documentation.

Since the Musketyr published Gradl-gaelyk-eclipse-plugin, we can develop a Gaelyk project in comfort of Eclipse IDE.

This tutorial shows how to start a Gaelyk project in Eclipse.


Course of action



  1. Download Gaelyk Template project
  2. Fix gradle.build
  3. Import project to Eclipse
  4. Set project WAR directory
  5. Set App Engine
  6. Refresh Gradle dependencies
  7. Run project




Download Gaelyk template project


You can download Gaelyk Template project from Gaelyk website or visit Gaelyk on Github. The current version - v1.2 - of Template project on Gaelyk website contains a build problem, which is already fixed, but it is not included in zip package of the Template project on Gaelyk websites.





Fix gradle.build


After downloading the package, it is necessary to change the file gradle.build.

eclipse { 
  classpath { 
    plusConfigurations += configurations.functionalTestRuntime 
  } 
} 


Import project to Eclipse


Import the project into Eclipse IDE with Gradle plugin:

File > Import






Set project WAR directory


After import set project WAR directory:




Set App Engine




Refresh Gradle dependencies


Next step is refresh dependencies:

Right click on Project name > Gradle > Refresh All



Run project


Then you run the project as a Web Application:

Right click on Project name > Run As > Web Application



Links