Sending an Email from a Rule
Some installations may require notifications to be sent based on events that are not covered by the automated system notifications. Rules can often be used to drive these notifications. The example below shows how to send an email from a rule.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE sailpoint PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<sailpoint>
<Rule language="beanshell" name="Test Email Sending" type="BuildMap">
<Description>Debugging Tool - Sends a sample email out via the email server.</Description>
<Signature returnType="Map">
<Inputs>
<Argument name="log">
<Description>
The log object associated with the SailPointContext.
</Description>
</Argument>
<Argument name="context">
<Description>
A sailpoint.api.SailPointContext object that can be used to query the database if necessary.
</Description>
</Argument>
</Inputs>
</Signature>
<Source>
// Library inclusions for BeanShell
import sailpoint.api.*;
import sailpoint.object.*;
import sailpoint.tools.*;
import java.util.*;
import java.lang.*;
import java.text.*;
// Point this to the "To" email address
String emailDest = "adam.hampton@example.com";
// Specify the email template name in tplName
String tplName = "SailPoint - Test Email Sending";
EmailTemplate template = context.getObjectByName(EmailTemplate.class, tplName);
if (null == template) {
log.error("ERROR: could not find email template [ " + tplName + "]");
return;
}
template = (EmailTemplate) template.deepCopy(context);
if (null == template) {
log.error("ERROR: failed to deepCopy template [ " + tplName + "]");
return;
}
Map args = new HashMap();
// Add all args needed by the template like this
args.put("testField1", "This is a test of template parameters.");
EmailOptions ops = new EmailOptions(emailDest, args);
context.sendEmailNotification(template, ops);
return;
</Source>
</Rule>
</sailpoint>
The BeanShell from this example rule can be used as a template for sending an email from any defined rule. Simply change the email template name, recipient, and template arguments to create the desired notification.
Using a Rule to Test Templates and Email Configuration (link)
For an overview of developing and using rules in IdentityIQ, see Rules and Scripts in IdentityIQ (link).
Using a Rule to Test Templates and Email Configuration
This example rule can also be used to test the email server configuration or to test any email template. Complete these steps to use the rule for testing purposes:
Note
To test email templates independently from the email server configuration without actually sending emails through the server, choose Email Notification Type: Redirect to File. This writes the email text to the specified file.
-
Set up an email server on Gear icon > Global Settings > IdentityIQ Configuration > Notification Settings.
-
Edit an email template to contain the desired message and import it.
-
Edit the "Test Email Sending" rule to include the desired "To" email address, email template, and arguments, and import the rule. (Rules are imported the same way as templates, as described in Importing Email Templates into IdentityIQ.)
-
Run the "Test Email Sending" rule from the IdentityIQ console to send the email.
> rule "Test Email Sending"
-
Examine the resultant email (either in the recipient's inbox or the redirect email file) to verify that the message appears as expected.
For an overview of developing and using rules in IdentityIQ, see Rules and Scripts in IdentityIQ (link).