开发者

Lift Mailer error: gnu.mail.handler.TextPlain cannot be cast to javax.activation.DataContentHandler

Using the following code:


sendMail(From(Props.get("email")), Subject("Test Email"), To("email@address"),
                   PlainMailBodyType("test email body"));

And in Boot.scala:


 System.setProperty("mail.smtp.starttls.enable","false");
    System.setProperty("mail.smtp.host", host)
    System.setProperty("mail.smtp.auth", "true")
    Mailer.authenticator = Full(new Authenticator {
        override def getPasswordAuthentication = new PasswordAuthentication(user, password)
      })

I get the following error:

2011-05-23 18:49:02,868 ERROR [pool-3-thread-4] n.l.u.MailerImpl [Logging.scala:239] Couldn't send mail java.lang.ClassCastException: gnu.mail.handler.TextPlain cannot be cast to javax.activation.DataContentHandler at javax.activation.MailcapCommandMap.getDataContentHandler(MailcapCommandMap.java:596) ~[activation-1.1.jar:1.1] at javax.activation.MailcapCommandMap.createDataContentHandler(MailcapCommandMap.java:550) ~[activation-1.1.jar:1.1] at javax.activation.DataHandler.getDataContentHandler(DataHandler.java:611) ~[activation-1.1.jar:1.1] at javax.activation.DataHandler.writeTo(DataHandler.java:315) ~[activation-1.1.jar:1.1] at javax.mail.internet.MimeUtility.getEncoding(MimeUtility.java:261) ~[mail-1.4.1.jar:1.4.1] at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1321) ~[mail-1.4.1.jar:1.4.1] at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2074) ~[mail-1.4.1.jar:1.4.1] at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:2042) ~[mail-1.开发者_如何学C4.1.jar:1.4.1] at javax.mail.Transport.send(Transport.java:117) ~[mail-1.4.1.jar:1.4.1] at net.liftweb.util.MailerImpl$$anon$1$$anonfun$$init$$1.apply(Mailer.scala:176) ~[lift-util_2.8.1-2.3.jar:2.3]

This code works on one box and not on another. Any ideas?


Alternative solution if you want to use the Jetty package that comes with your Linux distro.

The problem only seems to occur with the GNU implementation of JavaMail. If you can use the Sun implementation instead, it works fine, or at least it did for me.

Adding Sun's javamail: I took activation-1.1.jar and mail-1.4.1.jar that sbt had placed under the lib_managed/ folder of my Lift project, and placed them under /usr/share/jetty/lib/ on the server.

Removing GNU javamail: Unfortunately, commenting out the gnumail.jar from /etc/jetty/start.config wasn't enough to get rid of gnumail. Jetty somehow still found the gnumail.jar and now mails just crashed in a different way. To get things to work smoothly I had to uninstall libgnumail-java and therefore also libjetty-extra which depends on it (I'm using Ubuntu). If you need libjetty-extra you'll need a different way to ensure Jetty won't see gnumail.jar.


Apparently it is an issue in versions of Jetty < 6.1.25. http://olex.openlogic.com/packages/jetty/6.1.25 Something wrong with activation dependency. Switching to the latest version of jetty (7.3) fixed it!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜