Email notification using Java Mail API and Freemaker API in ADF application.

Email notification in Oracle ADF.

Sending Email using Java Email API and Freemaker template:

About  FreeMarker:  In FreeMarker you define templates, which are text files that contain the desired output, except that they contain placeholders like ${name}, and even some logic like conditionals, loops, etc. In your Java program you supply the actual values for these placeholders and the final output is generated based on this input.

How to send an email in ADF application:

1)      Create Fusion web application in Jdevloper.
2)      Add required jar as below on classpath
i)                    Freemaker.jar
ii)                   Javax.mail-1.5.0.jar
iii)                 Commons-email.jar

3)      Define Mail session on Weblogic server

4)      Add all below properties in mail session

i)                    Xxx.hostname=<your mail server>
ii)                   XXX.port=<your port number of mail server>
iii)                 XXX.username=<your email id>
iv)                 XXX.password=<your mail password>
5)      Use InitialContext to read the all properties defined in mail session

6)      Create freemaker file as save it as .ftl extension. Here in my case I am sending html content in mail so I have create file with html content and left placeholder to replace actual values at runtime. Place the same file in default domain of weblogic server.

<html>
<body>
Hi ${to},
<p style='color:red;'>${message}</p>
Regards,<br/>
${from}.
</body>
</html>

7)      How to read .ftl file in code
Freemaker api has class to load the template from server classpath and process the ftl file and replace all the placeholder in ftl file. Use below code for the same,

8)      How to send email using java mail api,

You can send html email using java mail api  and freemaker jar.

Happy learning !!!!.

Comments

Popular posts from this blog

React JS

WaterMark behavior in ADF

WebLogic Application Deployment & Shared Library