2

I'm having a really frustrating problem with Javamail.

So, simple non-encrypted, no-attachment e-mail works both in linux and Windows.

When I try to send attachment along with it, or send an e-mail using TLS encryption, javamail crashes on linux only, not on Windows.

Exception is thrown at Transport.send(msg), which isn't what I wrote.

Full stack trace is this.

java.lang.NullPointerException
        at org.jpackage.mail.inet.smtp.SMTPConnection.getResponse(SMTPConnection.java:814)
        at org.jpackage.mail.inet.smtp.SMTPConnection.getAllResponses(SMTPConnection.java:841)
        at org.jpackage.mail.inet.smtp.SMTPConnection.quit(SMTPConnection.java:537)
        at gnu.mail.providers.smtp.SMTPTransport.close(SMTPTransport.java:549)
        at javax.mail.Transport.doSend(Transport.java:205)
        at javax.mail.Transport.send(Transport.java:75)

Any possible reason for this? I'm just having a really frustrating time dealing with this application failing on Linux.

ghostJago
  • 3,381
  • 5
  • 36
  • 51
Don Spike
  • 21
  • 1
  • How do you expect someone to answer without seeing the code that causes this behavior? Also, you seem to have a mail provider from org.jpackage... what libraries are you using? – Jim Garrison Sep 08 '11 at 03:59
  • I'm using everything included in Javamail1.4.4 library, downloaded from the Sun's (or Oracle's) website. The code is really similar to what you'd find in the web when you search for Javamail example. – Don Spike Sep 08 '11 at 16:33

2 Answers2

3

I downloaded and examined the javamail 1.4.4 distribution from Oracle. Nowhere in the included jar files are there ANY org.jpackage.* or gnu.mail.* packages, so you must be getting them from somewhere else.

I suggest you clean up your classpath and eliminate the spurious packages, and try again.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • This totally solved it for me (was getting SendMailException: connection reset) --needless GNU mail package seemed to be getting in the way – Alkanshel Jun 11 '14 at 17:47
0

I experienced a similar issue with exact same exception. I ran a same code on the same OS (Windows) but in two different context (a DOS prompt and a JOnAS application server) and both didn't bring the same result: The mail was sent successfully on DOS prompt, but failed on JOnAS.

I activated the debug mode for mail session and compared the SMTP traces. They were more or less the same, except the username and password base64 values sent for authentication: I noticed that in DOS (working) version, the base64 converted password had padding (for instance, the password "test" was converted into "dGVzdA=="), but in JOnAS version (not working), the base64 converted password had no padding (the password "test" was converted into "dGVzdA"). This made the authentication fail.

The bad base64 encoding was caused by gnu-mail.jar and/or gnu-providers.jar libraries present in JOnAS default libs and which were loaded instead of the jar embedded in my WAR.

I fixed the issue by removing those jars from JOnAS default libs folder. After JOnAS restart, the mail was sent successfully.

morbac
  • 301
  • 4
  • 16
  • Another possible fix would be to change the password with something that has no padding when converted in base64. This is possible with password, but more difficult with username... – morbac Feb 22 '19 at 07:14