Send email

Description

This javascript action sends an email.

The Send email Action Javascript can be used to send an email. The email message can be defined in the action or loaded from the Repository. Placeholders can be used in the email template, allowing you to include data from fields in the current record in the message (e.g. {firstname}). Xbasic functions can be used in placeholders (e.g. Hello {upper(firstname)}. You can specify if the email should be sent immediately, or queued (by adding a new task to the Work Queue table). Since connecting to a SMTP server can be quite slow, in a high traffic application, it is generally a good idea to queue sending email messages.

You are responsible for processing the Work Queue. Simply adding a task to the Work Queue will not cause it to be processed unless some job reads the Work Queue and acts on the tasks in the Queue.

Used with the Grid and UX components.

Properties for Configuring Send email

E-mail Settings Properties

Send method

Specify if the e-mail should be sent using the built-in e-mail methods, or using a 3rd party e-mail service. Choices include Internal and SparkPost. Choose SparkPost to send an email using the SparkPost or SendGrid service.

SparkPost key

Your SparkPost or SendGrid API Key. If using SendGrid, prefix the SendGrid API key with sendgrid:.

You can enter <Project>, or leave this setting blank, to use the setting for the SparkPost key stored in Web Project Properties. This property appears when the 'Send method' is set to 'SparkPost'.

For more information about SparkPost API keys, see SparkPost API Keys.

For more information about SendGrid API keys, see SendGrid API Keys.

Use default e-mail settings

If you check this box, then the action will use the e-mail settings stored in the Web Project Properties

SMTP server

SMTP server property.

User name

User name property.

Password

Password property.

Port

TIP: With SSL, or TLS enabled, if you are using Gmail the port for the internal email methods is 465. For the .NET methods, use port 587.

SSL option

If you select the .Net Library, SSL and TLS operate identically.

.Net Library

Specify if the e-mail should be sent using Alpha Anywhere's internal 'sockets' object, or using methods in the Microsoft .Net Framework? If most case either option should be fine.

Message Properties

From

Specify e-mail address of the sender. You can use a component placeholder for the name. e.g. {sent_from}

From alias

Specify a friendly name for the from name. You can use a component placeholder for the name. e.g. {sent_from}

Subject

Specify the message subject. You can use component placeholders in the text. e.g. {subject}.

Send to

A comma or cr-lf delimited list of e-mail addresses. You can use a component placeholder for the e-mail address. e.g. {send_to}

CC

A comma or cr-lf delimited list of e-mail addresses. You can use a component placeholder for the e-mail address. e.g. {send_to}

BCC

A comma or cr-lf delimited list of e-mail addresses. You can use a component placeholder for the e-mail address. e.g. {send_to}

Load message from Repository

Specify if the message should use a saved template stored in the Repository. Email templates can be saved to the repository using the a5w_SaveToWebAppRepository() Xbasic function. See Web Application Repository for instructions on setting up the repository.

Saved message name

Specify the saved message template name. You can use component placeholders. e.g. {message_template_name}

Message body (HTML)

The HTML version of the message. You can use component placeholders in the text. e.g. {send_to}. You can call an Xbasic function to compute the message body by specifying this as the message text: {ExecuteFunction:myFunc} (where 'myFunc' is an Xbasic function defined in the Xbasic Functions section). The function that is called takes 'e' as an input parameter and must return the text of the message.

Message body (Plain text)

The plain text version of the message. You can use component placeholders in the text. e.g. {send_to}. You can call an Xbasic function to compute the message body by specifying this as the message text: {ExecuteFunction:myFunc} (where 'myFunc' is an Xbasic function defined in the Xbasic Functions section). The function that is called takes 'e' as an input parameter and must return the text of the message.

Attachments

A comma delimited list of filename attachments. You can use component placeholders for the filenames. e.g. {file1}.

Store message in outbox

Specify if the message should be stored in the outbox. Outbox name and connection string are defined in the Web Project Properties.

Send When Properties

Send when

Specify when the email should be sent. The 'Immediate' option sends the e-mail immediately. However, since connecting to a SMTP server can be slow, this option may not be suitable in a high traffic site. The 'AddToWorkQueue' option adds the task to the Work Queue so that another process can perform the work. Choices include Immediate, AddToWorkQueue.

Work queue format

Specify the format to use when adding the task to the Work Queue table. 'XbasicScript' stores a complete Xbasic script that the process that handles the work queue can just execute. 'XbasicProperties' stores the properties of the task using the Xbasic 'property_to_string()' function. 'JSON' stores the properties ot the task in JSON format. The process that handles the work queue will be responsible for converting the properties into Xbasic code. Choices include XbasicScript, XbasicProperties, JSON.

Client-side Events Properties

After message sent

Specify the name of a Javascript function to call after the message has been sent. The Javascript function gets passed 'e' which contains 'e.hasError - true/false' and 'e.errorText'.

Show confirmation message

Show an alert in the browser indicating whether the message was successfully sent or not. If you want more control over the text and display style of the message, you should set this option to false, and instead define an 'AfterMessageSent' event.

Confirmation message - success

Confirmation message - email sent or queued successfully. You can use language tags, <a5:r> and </a5:r> in the message.

Confirmation message - failure

Confirmation message - email not sent or queued because an error occurred. You can use language tags, <a5:r> and </a5:r> in the message.

See Also