This documents describes email templating, customisation and their priorities for Raven.
The platform can send emails to inform about specific events and necessary actions like the password reset, invitations to join, error notifications and more. You can customize the look and feel of these emails as well as disable them in your Tenant.
We use the Raven service by posting a special request to it’s API. These requests trigger email formation on basis of templates and values passed as arguments in the requests.
Generally template is text with placeholders that system replaces with concrete values at send moment. It takes the concrete values from the Raven’s API arguments call.
Platform chooses the templates by unique identifier passed as a part of Raven’s API
call URL (templateName
).
There are two classes of templates: Default and Custom.
Each template consists of set localized versions. Default templates has
English localization (locale=en
). Custom templates can have any locale.
When Raven sends email it selects template using the following priorities (the lower is number the higher is priority):
locale
locale=en
locale
locale
locale=en
These expressions add a flexibility and re-usability of templates. For the details see the handlebars docs.
You can set email templates by storing in the MongoDB (collection templates
). They
should be tenant specific (field tenantId
). Template record should look like this:
{
"tenantId": "mongo-object-id",
"locale": "en",
"name": "password-recovery",
"message": {}
}
tenantId
- id of tenant in which customized templates will be usedlocale
- language locale (default is en
)name
- name of the template that should be replaced by custom onemessage
- object that contains all about template (see description below). As template engine we’re using handlebars.First raven will try to find template by given name
, tenantId
and locale
.
If there’s no such record it will try to find template by given name
and tenantId
with locale=en
. If there’s no such record again it will just find any template
by given name
and tenantId
and use it. In case when raven unable to find any
one of mentioned templates it will use built-in system default templates.
For all the templates and their description continue reading the Platform emails and templates article.
Message field general structure (like in Mandrill):
{
"from_name": "{{COMPANY}} team",
"track_opens": true,
"track_clicks": false,
"auto_text": true,
"url_strip_qs": false,
"preserve_recipients": true,
"merge_language": "handlebars",
"global_merge_vars": [
{
"name": "CURRENT_YEAR",
"content": "2018"
},
{
"name": "APP_DOMAIN",
"content": "app.elastic.io"
}
]
}
global_merge_vars
- required variables to be pasted into corresponding handlebars expressionsHere are the Mandrill specific fields (see here for more description):
track_opens
track_clicks
auto_text
url_strip_qs
preserve_recipients
merge_language
This is how the password-recovery
template should look like:
{
"tenantId": "mongo-object-id",
"locale": "en",
"name": "password-recovery",
"message": {
"from_name": "{{{COMPANY}}} team",
"track_opens": true,
"track_clicks": false,
"auto_text": true,
"url_strip_qs": false,
"preserve_recipients": true,
"merge_language": "handlebars",
"html": "Some new custom html string (with css)",
"subject": "{{{COMPANY}}} password recovery",
"global_merge_vars": [
{
"name": "CURRENT_YEAR",
"content": "2018"
},
{
"name": "APP_DOMAIN",
"content": "app.elastic.io"
},
{
"name": "SUBJECT",
"content": "{{COMPANY}} password recovery"
},
{
"name": "COMPANY",
"content": "elastic.io GmbH"
},
{
"name": "LIST_ADDRESS_HTML",
"content": "list_address_html"
},
{
"name": "CODE",
"content": "12345"
},
{
"name": "FNAME",
"content": "TEST"
}
]
}
}
All other templates differ in message
, subject
and global_merge_vars
(whole message should be merged with Message field general structure, see above).
For all the templates and their description continue reading the Platform emails and templates article.