Skip to content

Latest commit

 

History

History
297 lines (237 loc) · 15.1 KB

README.md

File metadata and controls

297 lines (237 loc) · 15.1 KB

Modules

emailConfig

Configuration

config.js contains the configuration for the sendMail function. The config object must be completed for the sendMail function to work correctly. This object is passed to [the sendEmail function](#module_sendEmail..sendMail) with values from the current sheet environment via [the procParams object](#module_sendEmail..procParams).

Please see the documentation for the parameters in const config below. All parameter values are undefined by default.

sendEmail

Sending Email

The sendEmail() function is the main and only runner function for this script. To have this function respond to new form responses, please add sendMail() as an installable trigger in your project. Please see [the installable triggers documentation](https://developers.google.com/apps-script/guides/triggers/installable#google_apps_triggers) for more information.

Your project information must be added to this config object before the sendEmail() function will work correctly. Please see the documentation for [config](#module_emailConfig..config) for a description of required parameters.

For debugging this script, please see [the sendMail function](#module_sendEmail..sendMail) below or the [debug.js file](#module_debug) for more information.

debug

Debugging

The debugRunner function is equivalent to running sendMail(true) - all actions between debugRunner and sendMail(true) are equivalent. Both functions will send all runtime notifications to the email address listed in procParams.data.admin instead of the recipient listed in procParams.data.recipient. This is most useful for testing.

emailConfig

Configuration

config.js contains the configuration for the sendMail function. The config object must be completed for the sendMail function to work correctly. This object is passed to [the sendEmail function](#module_sendEmail..sendMail) with values from the current sheet environment via [the procParams object](#module_sendEmail..procParams).

Please see the documentation for the parameters in const config below. All parameter values are undefined by default.

Author: unforswearing

emailConfig~config : Object

Update const with values specific to your project.

Kind: inner constant of emailConfig
Properties

Name Type Description
admin string

Admin will receive error notifications

formName string

The name of the form used to add responses to your spreadsheet

recipient string

Add email addresses here. All form responses will be sent to any address added. Addresses may be for one individual or an array of addresses for multiple recipients.

emailFooter string

emailFooter specifies the html string to be used in the emails that are sent from this script. Leave blank if you do not require an email footer

sheetId string

Property sheetID is required for this script to work properly Properties formName and sheetId will be extracted from const formName and const sheet

sheetNameFilter string

sheetNameFilter is used to extract the form name from the sheet name. the 'responses' default is typical for most forms.

subjectFilter string

subjectFilter is used to create the email subject from the sheet name. the text in the subjectFilter will be added to the sheet name to generate an email subject. if you do not want the additional text in the email title you can leave this section blank -- use ''

sheetInfo Object

The first column is set to 'A' by default. To use a different first column modify the firstCol parameter to another column in your sheet.

sendEmail

Sending Email

The sendEmail() function is the main and only runner function for this script. To have this function respond to new form responses, please add sendMail() as an installable trigger in your project. Please see [the installable triggers documentation](https://developers.google.com/apps-script/guides/triggers/installable#google_apps_triggers) for more information.

Your project information must be added to this config object before the sendEmail() function will work correctly. Please see the documentation for [config](#module_emailConfig..config) for a description of required parameters.

For debugging this script, please see [the sendMail function](#module_sendEmail..sendMail) below or the [debug.js file](#module_debug) for more information.

See: config
Author: unforswearing

sendEmail~procParams

procParams is created using values from [the config object](#module_emailConfig..config). Do not modify the procParams object directly! The parameters in this procParams object will default to the imported config file, calculating information from the active sheet only where necessary.

Kind: inner property of sendEmail

sendEmail~activeSpreadsheet : Object

Get the spreadsheet object for the active spreadsheet. Uses the Google Apps Script [SpreadsheetApp class](https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app).

Kind: inner constant of sendEmail

sendEmail~sheetName : string

Use the activeSpreadsheet object to retrieve the name of the current sheet via the [getName)](https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#getName()) method.

Kind: inner constant of sendEmail

sendEmail~getLastColumnLetter() ⇒ string

A method to retrieve the letter of the last used column in the spreadsheet. Use getLastColumnLetter as the value for the [the config object](emailConfig~config) parameter data.sheetInfo.lastColumnLetter. This is set by default in the sendMail function.

Kind: inner method of sendEmail
Returns: string -

The last column letter as a string.


Example

// Example: modify the script to retrieve an arbitrary range
// from your Google Spreadsheet
const getLastRange = () => {
  let lastCol = getLastColumnLetter()
  return activeSpreadsheet.getRange(`A30:${lastCol}30`)
}

sendEmail~sendMail(debug) ⇒ void

'sendMail()` is the main runner function. Be sure to add this functiom as an installable trigger in your project. See [the installable triggers documentation](https://developers.google.com/apps-script/guides/triggers/installable#google_apps_triggers) for more information.

Debugging

sendEmail(true) to send all notifications to 'admin' for testing. The debugRunner function is equivalent to running sendMail(true) - all actions between debugRunner and sendMail(true) are equivalent. Both functions will send all runtime notifications to the email address listed in procParams.data.admin instead of the recipient listed in procParams.data.recipient. This is most useful for testing.

Kind: inner method of sendEmail

Param Type Description
debug boolean

specify whether the script should send errors to admin

sendMail~id

extract helper code and info from procParams (var parameters) assumption: parameters.helper contains an object of helper vars / funcs var helper = parameters.helper;

Kind: inner property of sendMail

sendMail~sheet

open the sheet for parsing

Kind: inner property of sendMail

sendMail~sheetInfo

sheetInfo = { firstCol, lastCol }

Kind: inner property of sendMail

####### sheetInfo.rangeString

Get the latest response range as text eg. "A10:G10"

Kind: static property of sheetInfo

####### sheetInfo.questions

get the values for question and latest response ranges

Kind: static property of sheetInfo

####### sheetInfo.submissionData[undefined]

change the date formatting if needed

Kind: static property of sheetInfo

sendMail~tsi

tsi === time stamp index

Kind: inner property of sendMail

sendMail~dataTable

create the submission info table and styles for html emails table rows will be pushed to the dataTable column in the loop below

Kind: inner property of sendMail

sendMail~tablestyle

add styles for full table and nest the dataTable rows in table tags

Kind: inner property of sendMail

sendMail~recipient

Use admin email address if debug is true, otherwise use the script default

Kind: inner property of sendMail

sendMail~sheetName

create email subject

Kind: inner property of sendMail

sendMail~logo

add a company logo if desired. otherwise, comment out the two lines below

Kind: inner property of sendMail

sendMail~emailFooter

create the email body

Kind: inner property of sendMail

debug

Debugging

The debugRunner function is equivalent to running sendMail(true) - all actions between debugRunner and sendMail(true) are equivalent. Both functions will send all runtime notifications to the email address listed in procParams.data.admin instead of the recipient listed in procParams.data.recipient. This is most useful for testing.

Author: unforswearing

debug~debugRunner(admin) ⇒ void

Using debugRunner()

This function is added as a convenience for testing the script againt the latest form response. To automate this process you may add this function as an installable trigger in your project. See [the installable triggers documentation](https://developers.google.com/apps-script/guides/triggers/installable#google_apps_triggers) for more information.

Kind: inner method of debug

Param Type Description
admin string

The email address to send errors