My jdev version is 12.1.3.
I've created a class file NewMail in viewcontroller view package.
During commit operation i'm initiating an e-mail from the view as per the code below .
If i give the complete path for picture.png, then i'm able to get the mail with image.
ADF throws null pointer exception if i dont give the full path, how to generalise as per ADF incase if i decide to put this picture.png inside webcontent folder.
package view;
import java.io.File;
import java.io.InputStream;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import oracle.jbo.domain.ClobDomain;
public class NewMail {
public static void sendenhancement_mail(final String user ) {
Runnable r = new Runnable() {
public void run() {
try{
String to = "xxxxx@xxx.com";
String from = "xxxxx@xxx.com";
final String username = "xxxxx@xxx.com";
final String password = "rrrr";
Properties props = new Properties();
props.put("mail.smtp.host", "rrrrr");
props.put("mail.smtp.socketFactory.port", "333");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "333");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
message.setSubject("Hi");
MimeMultipart multipart = new MimeMultipart("related");
BodyPart messageBodyPart = new MimeBodyPart();
String htmlText ="Hello"+"<img src=\"cid:image\">"+"<BR><B>Note: This is an automated E-mail.</B>";
messageBodyPart.setContent(htmlText, "text/html");
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart();
System.out.println("Working Directory = " +
System.getProperty("user.dir"));
DataSource fds = new FileDataSource(
"Picture.png");
messageBodyPart.setDataHandler(new DataHandler(fds));
messageBodyPart.setHeader("Content-ID", "<image>");
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport.send(message);
System.out.println("Sent message successfully....");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
catch (Exception e) {
System.out.println("Exception occured "+e);
}
}
};
Thread t = new Thread(r);
t.start();
}
}