Javamail 适用于 Windows,不适用于 Linux
我在使用 Javamail 时遇到了一个非常令人沮丧的问题。
因此,简单的非加密、无附件电子邮件在 Linux 和 Windows 中都可以使用。
当我尝试发送附件时,或者使用 TLS 加密发送电子邮件时,javamail 仅在 Linux 上崩溃,而不是在 Windows 上。
Transport.send(msg) 抛出异常,这不是我写的。
完整的堆栈跟踪是这样的。
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)
这有什么可能的原因吗?我只是在处理这个在 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从 Oracle 下载并检查了 javamail 1.4.4 发行版。包含的 jar 文件中没有任何
org.jpackage.*
或gnu.mail.*
包,因此您必须从其他地方获取它们。我建议您清理类路径并消除虚假包,然后重试。
I downloaded and examined the javamail 1.4.4 distribution from Oracle. Nowhere in the included jar files are there ANY
org.jpackage.*
orgnu.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.
我遇到了类似的问题,但有完全相同的异常。我在相同的操作系统 (Windows) 上但在两个不同的上下文(DOS 提示符和 JOnAS 应用程序服务器)中运行相同的代码,但两者都没有带来相同的结果:
邮件在 DOS 提示符下发送成功,但在 JOnAS 上发送失败。
我激活了邮件会话的调试模式并比较了 SMTP 跟踪。它们或多或少是相同的,除了发送用于身份验证的用户名和密码 base64 值:我注意到在 DOS(工作)版本中,base64 转换后的密码有填充(例如,密码“test”被转换为“dGVzdA= =”),但在 JOnAS 版本(不起作用)中,base64 转换后的密码没有填充(密码“test”被转换为“dGVzdA”)。这导致身份验证失败。
错误的 base64 编码是由 JOnAS 默认库中存在的
gnu-mail.jar
和/或gnu-providers.jar
库引起的,并且加载了这些库而不是嵌入在我的战争。我通过从 JOnAS 默认库文件夹中删除这些 jar 解决了这个问题。 JOnAS重启后,邮件发送成功。
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/orgnu-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.