I am using below code send email via java adapter in MFP 7.0 it has attachment also.
try {
StringBuffer sb = new StringBuffer();
try {
sb.append("<p style='font-family:Sans-serif;font-size: 12px'>Dear Xyz,<br><br>Attachment :</p>");
sb.append("<p style='font-family:Sans-serif;font-size: 12px'>Regards, <br><br> Team");
String mailHost = "10.x.x.x";
String mailFrom = "[email protected]";
String mailTo = email;
String mailSubject = "Subject";
String mailBody = sb.toString();
String mailAttachment = "" + fileName;
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", mailHost);
Session session = Session.getDefaultInstance(properties);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(mailFrom));
Address[] toAddress = null;
if (mailTo != null) {
toAddress = InternetAddress.parse(mailTo);
message.setRecipients(Message.RecipientType.TO, toAddress);
}
message.setSubject(mailSubject);
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(mailBody, "text/html");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart();
String attachmentLocation = mailAttachment;
DataSource source = new FileDataSource(attachmentLocation);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(new File(attachmentLocation)
.getName());
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport.send(message);
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
I am getting the below error.
java.lang.ClassCastException: org.apache.geronimo.mail.handlers.HttpHandler cannot be cast to javax.activation.DataContentHandler jax rs
Kindly suggest on this issue as the class HttpHandler is from worklight-jee-library.jar which i am unable override. Is their any alternative for sending email with attachment from Java adapter.
We do it a bit differently...
In the application logic:
And the Java code (stored in server/java/com/SendMail/SendMail.java) - you will obviously need to change the implementation details...: