sfSendEmail

Requests the server to send an email. The email configuration is picked from an email template that must already be present in the domain.

When this function is executed in the browser or in the mobile app, it sends a request to the server for the email to se sent out. The email is always sent out from the server (and never directly from the browser or the mobile app). The report of the form and/or its form files can also be sent as an attachment with the email.

The status of the email requests can be viewed in the email queue.

Syntax

sfSendEmail (emailTemplateName, immediateMode, attachmentTypes, formId, filterExpression, callback)

Parameters

Name

Type

Mandatory

Description

Name

Type

Mandatory

Description

emailTemplateName

string

yes

Name of the email template that contains the email configuration like the recipients, email subject and email body.

immediateMode

boolean

yes

Indicates if the email should be sent immediately upon the receipt of the request or can be sent at a delayed interval that is usually between 5 to 15 minutes.

attachmentTypes

string

no

Indicates the attachment(s) to be sent along with the email. The possible attachment types are:

FORM_DOCUMENT - Attaches the report of the form.

FORM_FILES - Attaches the files linked to the form.

More than one attachment types can be mentioned separated by comma. If not mentioned, the email is sent without an attachment.

formId

guid

no

Identifier of the form for which the email should be sent out. If the form identifier is mentioned, the report as well as the files of the mentioned form is used. Also, if there are replacement tags in the email template configuration, they are replaced by the data from the mentioned form.

If no identifier is mentioned, the current form in the context is considered.

filterExpression

string

no

Regular expression to filter the form files that should be included as attachments. Applicable only if attachmentTypes contains FORM_FILES.

callback

function

no

Code block to be executed after the request to send the email has been sent.

See callback function.

Usage examples

Example 1

Let us assume an email template named TankCapacityCheckReminder. To send out an email immediately on click of a button named SendCheckReminder,

sfRegisterFieldCallback("control_sendcheckreminder", "click", function(value, index) { sfSendEmail ("TankCapacityCheckReminder",true); }

It will send out an email to the recipients mentioned in the email template with the email subject and the email body mentioned in the email template.

Example 2

Let us assume an email template named InspectionCompleted. To send out an email immediately when the current inspection form is completed,

if () { sfSendEmail ("InspectionCompleted",true); }

Example 3

Consider the example above to send an email when the current inspection form is completed. To send out the email along with the report of the completed form,

if () { sfSendEmail ("InspectionCompleted",false,"FORM_DOCUMENT"); }