Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Warning

Looking for the documentation on the newest versions of SIL Engine and the Simple Issue Language for Jira 8 for Server/Data Center? Click here !

Contents

Table of Contents

Email Templates

Email templates represent one of the first features of this app. Its initial implementation only allowed for simple variables to be injected into the templates. They are now based SIL SIL™ Template Language and therefore their usage got a lot easier than before.

To be short the email templates mechanism is prefered and recommended way of sending emails from SIL SIL™ scripts. The send Email() routine packs powerful tools.

Email templates obey the same rules as those presented in the general STL page above and in the previous chapter with some notable differences, introduced just to make your life easier.

...

Make sure you read sendEmail() routine documentation to see how it is called, and notice that it has many overloads.

Mail Templates Base Directory

Unlike usual templates, presented before, email templates got their own base directory, and you can configure that directory here. This is both for historical reasons and because we recognized the importance of organizing mail templates in our integration projects. Under this directory, you may organize language folders, which that will be used to internationalize your email messages. This feature is controlled in the above configuration screen (Mail language on: Receiver). The default is set on Sender which simply Sender that simply uses the declared language of the sender user, whoever s/he may be.

...

If we look at the French support, you will see that above we use the same template for all the French speakers, no matter what country they come from. And if we look at the Romanian support, we'll see that, because the internationalization directory ('ro') is missing, it will default to the MAIL_TEMPLATES_BASE/template.tpl.

 


Note
titleAdvice

If you need to send the same mail in multiple languages, do not mix templates used with the executeTemplate() routine with the sendEmail() routine. Keep them separate. Of course this is valid only if templates are different, if you use the same for both emails and something else, put them in the same place.

...


Additional Injected Variables

In addition to the variables from the context, sendEmail routine defines a few more variables,  injected into the topmost context, as strings in your template:

  1. recipient - the recipient (s) - if there are more than 1 recipient, recipients are joined together with a comma between them

  2. sender - the sender - but only if the sender is defined.

Usage Examples

Do you have cookies?

To exemplify the usage, let's write a post function:

...

Variables from our script are exposed into the template (cookie seems unused, but it is not!). This template must run in an issue context, since it refers the pre-defined variables from the issue.

Bruce Wayne

Let's try to categorize our customers on either Batman's side, the evil side or neutral side. If we create a customfield customerId, which that is a numeric code provided by the user, the following postfunction will complete a variable (custName) with the company name. In production systems, I suppose, you may want to get that customer name from a database (see the sql() routine). For this example, a bit of logic will allow us to distinguish between the Batman's owned corporation and ... eh, a phantom, evil, one:

...

Code Block
titletemplate.tpl
<html>
<body>
Hello $reporter$ from $custName$, the sender $sender$ announces you that the assignee for issue $key$ is $assignee$ and that work has started
$!
//this is a simple script, not carrying too much meaning, but just used as an example.
for(number i = 0; i < 3; i++) {
    $
    <p>
        Hip!
    </p>
    $!
}
$
<p>
    Hooray!
</p>
</body>
</html>

 


Now, Hip! Hip! Hip! Hooray! will be put in your email (4 paragraphs). Use standard CSS to nicely format your html email messages.