Categories
Bizagi Tips and Tricks

How to send emails from an expression

I had situations in the past where I was required to send a notification directly from an expression. After some trial and error, I managed to find a way. Here is an example of how to send a notification directly from an expression. The first thing I did was to create a library rule. The purpose is to have all the code in one place, in case I need to make any changes down the road. Otherwise, I will have to replicate the change in all the expressions where I’ve used the email method.

The solution was to use the CMailer class.

var sEmail = "recipient@mail.com";
var sSubject = "HTML email with CMailer";
var sMessage = "<p>Hello Developer,</p><p>This email was sent from an expression</p>";

CMailer.sendEmail(sEmail, sSubject, sMessage);

The body of the notification supports HTML so you could easily build some modern, nice-looking email templates.