Sending Email

Workflow rule services can send email notifications to system users about changes that are relevant for these users. For example, when the work request is approved or rejected, the system should notify the user who created the work request about the status change.

The MailSender class provides the send() method to send email notifications. Here is a simple usage example:

// subject is an application parameter
String subject = Configuration.getActivityParameterString("AbSolutionsMyAdn", "ApproveMessageSubject");

// message body is an application parameter
String text = Configuration.getActivityParameterString("AbSolutionsMyAdn", "ApproveMessageBody");

// system email account is an application parameter
String from = Configuration.getActivityParameterString("AbSolutionsMyAdn", "SystemEmail");

// recipient email
String to = ...
// prepare the message MailMessage message = new MailMessage(); message.setSubject(subject); message.setText(text); message.setFrom(from); // send email new MailSender.send(message);

The email parameters (subject, message etc) can be retrieved from the afm_activity_params table (as in this example), sent from the user interface, or hard-coded in the workflow rule Java code.

By default, the messages are encoded using the content type. You can send email messages in the HTML format. In this case, the email text can contain valid HTML tags and attributes. You need to set the message content type as follows:

message.setContentType("text/html; charset=UTF-8");
...
new MailSender.send(message);

The email server properties are defined in the WEB-INF\config\mail.properties configuration file. The MailSender.send() method uses these properties automatically. You can change the default content type for all mail messages from text to HTML (see the example in mail.properties). The content type defined in mail.properties impact mail messages for which you do not call message.setContentType() from Java.

See Also

Configuring Email