Expand my Community achievements bar.

javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;

Avatar

Level 3

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.

3 Replies

Avatar

Level 10

Can you get that Java code (Except for MessageServiceGateway) to work outside of AEM. Try getting that to work from Eclipse and see if it successfully sends an attachment. I was just testing that today - something like:

Properties props = new Properties();

        props.put("mail.smtp.auth", "true");

        props.put("mail.smtp.starttls.enable", "true");

        props.put("mail.smtp.host", mailserver);

        props.put("mail.smtp.port", "587");

        Session session = Session.getInstance(props,

                new javax.mail.Authenticator() {

                    protected javax.mail.PasswordAuthentication getPasswordAuthentication() {

                        return new javax.mail.PasswordAuthentication(username, password);

                    }

                });

        try {

            Message message = new MimeMessage(session);

            message.setFrom(new InternetAddress("foo@hotmail.com"));

            message.setRecipients(Message.RecipientType.TO,

                    InternetAddress.parse(toaddress));

            message.setSubject(subject);

            message.setText(message2);

            // JavaMail 1.4

            // creates multi-part

            Multipart multipart = new MimeMultipart();

            MimeBodyPart attachPart = new MimeBodyPart();

            String attachFile = "webform.html";

            attachPart.attachFile(attachFile);

            attachPart.setContent(body, "text/html");

            multipart.addBodyPart(attachPart);

            // sets the multi-part as e-mail's content

            message.setContent(multipart);

            Transport.send(message);

Avatar

Level 3

Hi Donald,

I tried to send mail outside AEM, but we getting connection time out exception.

Thanks,

Akhila

Avatar

Administrator

Can you please share the exception and error?

I tested Adobe Experience Manager Help | Creating custom AEM workflow steps that send email messages , it worked for me.

-Kautuk



Kautuk Sahni