Notify - Templated Notification Bodies
Introduction
This feature enables you to generate notification bodies from predefined HTML templates. This can include information from your application's database as well as embedded images.
For example, you could have an HTML template for generating a trade confirmation, which includes an embedded logo and trade data from the application's database:
After you have created the HTML template and any embedded image files, load these to FILE_STORAGE. (Behind the scenes, the email builder uses the Document Generator to create the email bodies.) Once the files are in the correct location, you can use them to generate your email bodies.
This feature is currently supported by these Gateway types:
- SendGrid
Configuration
Before you can send emails, you must:
The same email template will work with both gateways.
HTML templates
Sourced data to be displayed in the email
There are examples of how to structure the data in your HTML templates in our Document Generator pages.
Note that the data referenced in the email bodies is queried by the tableName
and tableEntityId
fields, which we look at in detail below. At the moment you can only query a single record per email.
Embedding images
These can be referenced in the HTML template with the name of the file. The image files need must be uploaded to file storage and linked to the template as assets.
<img
src="./genesis-logo.png"
alt="Logo"
width="140"
style="max-width: 140px; width: 100%; display: block; border: 0px; height: auto !important;"
/>
CSS
The styling must be defined inline in the HTML template. If the CSS file is linked to the template as an asset, as it might be for standard PDF generation, it will be sent with the resulting email as an attachment. In this case, most email clients will fail to render the content correctly.
Sending emails with templated body content
Creating the notification
In order to use this feature, additional parameters are exposed on the EVENT_NOTIFY_INSERT event.
templateRef
tableName
tableEntityId
Use the templateRef
field to specify the template to use for generating the content. You can specify either a unique ID in the FILE_STORAGE table or the file name if the unique ID is not known.
If you want to include details from a record in the database (such as the record of a specific trade), use the tableName
and tableEntityId
fields to identify the record. The record is resolved and automatically added to the document generation data context under a key, which is the table name converted to lower camel case.
For example, if the notification is triggered by an update on the TRADE table, then the trade record will be added to the data context under the key 'trade'. You can then reference fields from the linked entity in your template, with this syntax:
<td th:text="${trade.tradeId}">Trade ID</td>