OIM 11G R2 PS2 : Send Email using the NotificationService and Custom Email Template

In this post, I will list down the code to send an email notification from event handler or a scheduled task to send out an email notification.

public OIMClient getOIMClient(String oimUserName, String oimPassword,
            Object oimURL) throws LoginException {
        java.util.Hashtable env = new java.util.Hashtable();
        env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_FACTORY_INITIAL,
                oracle.iam.platform.OIMClient.WLS_CONTEXT_FACTORY);
        env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_PROVIDER_URL, oimURL);
        oracle.iam.platform.OIMClient client = new oracle.iam.platform.OIMClient(
                env);
        client.login(oimUserName, oimPassword.toCharArray());
        return client;
    }

    public void sendEmail(String managerLogin, String roleApprover,
            String beneficiaryID, String reqId, String roleName,
            String requesterDisplayName) throws LoginException,
            UserDetailsNotFoundException, EventException,
            UnresolvedNotificationDataException, TemplateNotFoundException,
            MultipleTemplateException, NotificationResolverNotFoundException,
            NotificationException {
        OIMClient oimClient = getOIMClient("xelsysadm", "password",
                "t3://localhost:14000");
        oracle.iam.notification.api.NotificationService notsvc = oimClient
                .getService(oracle.iam.notification.api.NotificationService.class);
        oracle.iam.notification.vo.NotificationEvent notevent = new oracle.iam.notification.vo.NotificationEvent();
        String[] receiverUserIds = { managerLogin, roleApprover };
        notevent.setUserIds(receiverUserIds);
        notevent.setTemplateName("Custom Email Template Name");
        java.util.HashMap templateParams = new java.util.HashMap();
        templateParams.put("usr_key", beneficiaryID);
        templateParams.put("request_id", reqId);
        templateParams.put("role_name", roleName);
        templateParams.put("requester_name", requesterDisplayName);
        notevent.setSender(null);
        notevent.setParams(templateParams);
        System.out.println("Sending Email");
        notsvc.notify(notevent);
    }

Comments

Popular posts from this blog

OIM 11g R2 PS2 : SOA Approval Workflow Sample

OHS 12c (12.1.3) webgate deployment and configuration

Oracle Identity Manager (OIM) Interview Questions