javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
Hi All,
We are trying to send an email from a service. The mail contains an HTML body and an attachment. Below is the code we are using to send email.
DataSource source = new ByteArrayDataSource(bytes, "application/pdf");
MimeMultipart multipart = new MimeMultipart();
// Create the attachment part
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
attachmentBodyPart.setDataHandler(new DataHandler(source));
attachmentBodyPart.setFileName("attachment.pdf");
multipart.addBodyPart(attachmentBodyPart);
// Create the HTML Part
MimeBodyPart htmlBodyPart = new MimeBodyPart();
htmlBodyPart.setText("<p>sdsds sdsdsd</p>") , "text/html");
multipart.addBodyPart(htmlBodyPart);
// Set the Multipart's to be the email's content
email.setContent(multipart);
MessageGateway<HtmlEmail> gateway = messageGatewayService.getGateway(HtmlEmail.class);
gateway.send(email);
We are getting an exception as
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
boundary="----=_Part_60_1916610660.1516864876551"
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:896)
at javax.activation.DataHandler.writeTo(DataHandler.java:317)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1574)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1840)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1119)
... 132 common frames omitted
It is in AEM 6.1. We tried below fixes, unfortunately none of them worked.
1. MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
mc.addMailcap("message/rfc822;; x-java-content- handler=com.sun.mail.handlers.message_rfc822");
2. Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
Do any one has any suggestion please.
Thanks in advance.