Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaMail is eating my headers! (UPDATED)

C Gamache
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This problem defies logic! I'm totally at a loss to solve it...

It started with converting my projects to Maven projects mostly for dependency management. Everything compiles, and appears to work fine in Eclipse.

I have a class with a main() method that I run to send out emails with attachments. It uses JavaMail. I can run the class within Eclipse and it functions properly. But, if I package it into a Runnable jar and try to run it with the same JVM eclipse is using, JavaMail omits the headers form the email. I can verify this by viewing the output of msg.writeTo() and comparing it to the debug output from JavaMail. It's missing the To, From, Subject, and Multipart boundary headers (and the rest....), but it has the To and From to use for contacting the SMTP server for mail delivery (as is viewed from the debug output from JavaMail, MAIL FROM and RCPT TO). No exceptions being thrown, it simply won't send the headers. I've reproduced this on Linux and Windows, running the same version of JDK. I've peeked inside the JAR and nothing is missing.

I've paired everything down to the most basic set dependencies I can (and still have it run) but it exhibits the same behavior.

I'm still exporting a runnable jar using Eclipse, and not using any fancy maven build plugins.

To add to this problem, the source code downloadble from Maven central repos for JavaMail doesn't match the executing code. It's almost impossible to debug!

Nothing's changed except for the dependencies. It is true I've taken the opportunity to upgrade some of the referenced JARs but I've tried several different versions of JavaMail, and all have this problem. JavaMail doesn't advertise that it is dependant on anything except activation AFAICT, and that has stayed the same from pre-mavenization to post-mavenization.



The conflict was with axis2 1.5.1 depending on org.apache.geronimo.specs:geronimo-javamail_1.4_spec ... When I excluded that dependency, everything worked again. So the new question is how to protect one's self from that sort of conflict! Who knows what other problems I might have introduced by making that exclusion.... Scary stuff, don't you think?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic