EmailTemplate interface

A JavaScript object implementing the EmailTemplate interface represents one of the email templates defined in the System Management user interface.

Construction

Create a new EmailTemplate object with O.email.template().

Usage

Construct an EmailTemplate object. Generate the message text for each email using the allowed HTML subset, then call deliver() on the template object to send an email.

Interface

property name

The name of the template.

property code

The API code of the template, or null if the template doesn’t have an API code.

function deliver(toAddress, toName, subject, messageText)

Send an email. The from address is set in the email template.

This function will throw an exception unless the pSendEmail privilege is requested in the privilegesRequired key in the plugin’s plugin.json file.

Argument Example Purpose
toAddress "test@example.com" Email address of the recipient
toName "Test User" Display name of the recipient
subject "Test Notification" Subject of the email
messageText See below HTML text of the email

The message text is an HTML fragment using a restricted subset of HTML. The HTML must be well formed or an exception will be thrown.

A plain text version of the email will automatically be generated from the HTML message text.

Message text HTML subset

Your HTML message should not include any top level containers such as <html> or <body>, as these are part of the email template.

The following HTML is supported in message text:

Block elements for text

  • <p>
  • <h1>
  • <h2>
  • <blockquote>
  • <p class="description"> (indented, no margin above)

Block elements

Enclose block elements for text in these elements.

  • <div class="box">
  • <div class="footer">

Unclosed HTML tags

  • <hr>
  • <br>
  • <img> (ignore in plain text version)

Links

To render correctly in the plain text version, links must use one of the constructions below:

  • <p class="button"><a href="[url]"> ... </a></p> (call to action button)
  • <p class="link0"> ... <a href="[url]"> ... </a> ... </p> (link)
  • <p class="link1"> ... <a href="[url]"> ... </a> ... </p> (indented link)
  • <p class="action"> ... <a href="[url]"> ... </a> ... </p> (action link, only the link is output in the plain text version)

Other links will be omitted from the plain text output.