I am trying to trigger email as part of my workflow to multiple users using a set of specific templates(newA, newB, newC) that I have defined in EmailTemplates already to different user(launcher, abc.com,cde.com). The email trigger does not work. Below is my code.
import org.apache.commons.logging.Log;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import sailpoint.api.SailPointContext;
import sailpoint.object.EmailOptions;
import sailpoint.object.EmailTemplate;
import sailpoint.object.Identity;
Identity launcher_obj = context.getObjectByName(Identity.class, launcher);
String launcherDisplayName = (String)launcher_obj.getDisplayName();
List UserList = usr;
Map vars = new HashMap();
vars.put("userList", UserList);
vars.put("launcherDisplayName", launcherDisplayName);
Map<String, String> recipientsWithTemplates = new HashMap<>();
recipientsWithTemplates.put("launcher", "NewA");
recipientsWithTemplates.put("abc.com", "NewB");
recipientsWithTemplates.put("cde.com", "NewC");
void sendNotificationEmail(SailPointContext context, String emailAddress, String templateName,
Map variables, String recipientName) {
try {
EmailTemplate template = context.getObjectByName(EmailTemplate.class, templateName);
EmailOptions options = new EmailOptions();
options.setTo(emailAddress);
options.setVariables(variables);
context.sendEmailNotification(template, options);
log.debug("Mail has been successfully sent to " + recipientName +
" using template " + templateName);
} catch (Exception e) {
log.error("Failed to send email to " + recipientName +
" using template " + templateName, e);
}
}
for (Map.Entry<String, String> entry : recipientsWithTemplates.entrySet()) {
String recipient = entry.getKey();
String templateName = entry.getValue();
String recipientEmail;
if ("launcher".equals(recipient)) {
recipientEmail = (String)launcher_obj.getEmail();
} else {
Identity recipientObj = context.getObjectByName(Identity.class, recipient);
recipientEmail = (String)recipientObj.getEmail();
}
sendNotificationEmail(context, recipientEmail, templateName, vars, recipient);
}