I know similar questions have been asked many times befor, but I think this one slitly different :)
I'm writing a maven report plugin which will send emails to a list of users. I now have the problem, that the code seems to be working fine when I run it with java5, but failes with java6. Actualy the plugin is writen in Groovy and uses the commons-email utilities to send a html message:
HtmlEmail email = new HtmlEmail();
email.setHostName(mailhost);
email.setSmtpPort(mailport);
email.setFrom(args.from);
email.addTo(args.receiver);
email.setSubject(args.subject);
email.setHtmlMsg(args.htmlmessage);
email.setDebug(log.isDebugEnabled());
email.send();
The project has dependencies to the javax.mail:mail:1.4.1 and the javax.activation:activation:1.1.1.
If I run a maven project using my new plugin, I'm getting this exception with java6:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
boundary="----=_Part_0_11139111.1262007863993"
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:676)
at javax.mail.Transport.send0(Transport.java:189)
With java5 I don't have any problems.
I tried the following workarounds:
Add the mailcap config programmatically:
// add handlers for main mail MIME types MailcapCommandMap mc = (MailcapCommandMap)CommandMap.getDefaultCommandMap(); mc.getMimeTypes().each{ println "Original MIME-TYPE: $it" } mc.getAllCommands ("multipart/mixed").each { println "Original COMMAND: $it" } 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("multipart/mixed;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed"); mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822"); CommandMap.setDefaultCommandMap(mc); MailcapCommandMap mc2 = (MailcapCommandMap)CommandMap.getDefaultCommandMap(); mc2.getMimeTypes().each{ println "Replaced MIME-TYPE: $it" } mc2.getAllCommands ("multipart/mixed").each { println "Replaced COMMAND: $it" }
This also does not work with java6, but it really shows that the requested mimetype is not registered in the mailcap (see loops with 'println' log statments).
Original MIME-TYPE: image/jpeg Original MIME-TYPE: image/gif Original MIME-TYPE: text/* Replaced MIME-TYPE: message/rfc822 Replaced MIME-TYPE: multipart/* Replaced MIME-TYPE: text/plain Replaced MIME-TYPE: text/xml Replaced MIME-TYPE: multipart/mixed Replaced MIME-TYPE: text/html Replaced MIME-TYPE: image/jpeg Replaced MIME-TYPE: image/gif Replaced MIME-TYPE: text/* Replaced COMMAND: javax.activation.CommandInfo@1e5d007 Replaced COMMAND: javax.activation.CommandInfo@bc8f01
I created a file called 'mailcap' and placed it in the 'META-INF' directory of the plugin (see http://java.sun.com/j2ee/1.4/docs/api/javax/activation/MailcapCommandMap.html). But this does not get picked up at all.
So my question is, whether someone has any idea on how I get the code/configuration working on java5 and java6 :)