Don Spike
Don Spike

Reputation: 21

Javamail works on Windows, not on Linux

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.

Upvotes: 2

Views: 801

Answers (2)

morbac
morbac

Reputation: 349

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.

Upvotes: 0

Jim Garrison
Jim Garrison

Reputation: 86774

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.

Upvotes: 3

Related Questions