This post will describe how to send email from ADF Web application.
2 ways (which I know) to achieve this:
2 ways (which I know) to achieve this:
- Use the Apache Commons Email. [This can be used while deploying in GlassFish server. I haven't tried myself yet in Glassfish].
- Use the Javax Mail API's along with the MailSessions configuration in Weblogic Server.
Use Apache Commons Email.
- Download the commons-email-1.3.3-bin.zip from Apache Commons Email.
- Extract and add the commons-email-1.3.3.jar to the Project Library.
- Use the below code to send email in your code.
import org.apache.commons.mail.DefaultAuthenticator; import org.apache.commons.mail.Email; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.SimpleEmail; public static void sendEmail() throws EmailException { Email email = new SimpleEmail(); email.setHostName(
"smtp.gmail.com"
); email.setSmtpPort(
587
); email.setAuthenticator(new DefaultAuthenticator("
XXXXX
", "
XXXXX
")); email.setSSLOnConnect(true); email.setFrom("
xxxx@xxxx.com
"); email.setSubject("
Subject of the Email!!
"); email.setMsg("
First Line in the Message Body.\nSecond Line.
"); email.addTo("
yyyy@yyyy.com
"); email.send(); System.out.println("Email Sent successfully to yyyy@yyyy.com"); }
- More samples are available in Apache Commons Email website.
Use JavaX Mail APIs.
- Javax mail API's are available as part of the Jdev install (Jdev 12.1.3). This file is available under %MIDDLEWARE_HOME%\Oracle_Home\oracle_common\modules\javax.mail_2.0.0.0_1-4-4.jar
- Add this jar file to the Project Library.
- You can configure the mailserver details in the Weblogic server. The Weblogic server configuration and the code to send email is detailed in the Lalit Kapoor's Sending E-Mail From an ADF Application Deployed on WebLogic Server.
- I have a created a word document with the configuration steps and the code, which you can download from here.
Feel free to point out if anything is missing/wrong in this blog.
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHi Lucky,
DeleteWhere is this error coming ? When you try to compile or when you try to run ?
Cheers
AJ
The error appears in the source code a red line under the email.setAuthenticator(new DefaultAuthenticator("dildar.singh@oracle.com", "XXXXX")); when I hover over the line i get the message java.mail not allowed.[Java cloud service].
DeleteDid you add the jar file to your Project Library ? Please double check the import statements.
DeleteCan you please attach you code here or send the file to anoopjohny@gmail.com. Which Jdev version are you using ? I can then try to replicate.