Search This Blog

Wednesday, March 24, 2010

Email Notification when a User is Created in OIM

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class JavaMail
{


public void sendEMail(String firstName,String emailId,String userPassword)
{


try
{

StringBuffer stringBuffer=new StringBuffer();

Properties prop=System.getProperties();
prop.setProperty("mail.smtp.host","xyz.wmv.abc");
Session session=Session.getDefaultInstance(prop);
MimeMessage message=new MimeMessage(session);

stringBuffer.append("Hi, "+firstName);
stringBuffer.append("

Thank you for registering! We are pleased to welcome you to Test Mail.

");
stringBuffer.append("

To start using Test Page right now, please go to http://testoim:8080/xlWebApp/ and login using the following information:

");
stringBuffer.append("

Login: "+emailId+"
");
stringBuffer.append("Password: "+userPassword+"

");
stringBuffer.append("

If you have any difficulties logging into Test, please reply to this email with a description of what you are encountering and we will respond back as soon as possible.

");
stringBuffer.append("

Thank you,

");
stringBuffer.append("

Test Company
");
stringBuffer.append("Test Administration

");

//From Email Address goes here...
message.setFrom(new InternetAddress("oimadmin@test.com"));

//To Email Address goes here..
message.addRecipient(Message.RecipientType.TO,new InternetAddress(emailId));
message.setSubject("***Welcome to Test! You are registered.***");
message.setContent(stringBuffer.toString(),"text/html; charset=UTF-8");
Transport.send(message);

}
catch(MessagingException e)
{
e.printStackTrace();
}

}



}

Steps :

1. Create a jar file from this code by changing the host name in the code.
2. Create the adapter in OIM and put it as a dependant on successful user creation and mail will go to the user from oimadmin@test.com with his userid and password.

Please mail me if you have any questions.

Thanks

2 comments:

  1. I'm going to test this Solution, because I cannot do it through OIM Email Templates...

    Thanks!

    ReplyDelete
  2. How do you send an acknowledgment email notification to the initiator of a request? For example, the email will contain a tracking ID so that the user can track the status of their request in OIM11g (11.1.1.3).

    ReplyDelete