gpt4 book ai didi

logging - JavaMail 的 DCH 类错误

转载 作者:行者123 更新时间:2023-12-04 01:34:04 25 4
gpt4 key购买 nike

我正在尝试使用 Glassfish 3.1 提供的 jar 文件在 Java EE 6 中使用 JavaMail 设置一个简单的日志记录测试。关于这个主题似乎有很多问题,但我还没有找到任何有帮助的答案。我的测试代码如下所示:

import java.util.logging.Logger;

public class MyClass {
private static final Logger LOGGER = Logger.getLogger("MyClass");

public static void main(String[] args) {
LOGGER.severe("This is a test");
}
}

我的 logging.properties 文件包含以下内容:
com.sun.mail.util.logging.MailHandler.mail.smtp.host={my mail hub FQDN}
com.sun.mail.util.logging.MailHandler.mail.smtp.port=25
com.sun.mail.util.logging.MailHandler.mail.to={me}
com.sun.mail.util.logging.MailHandler.mail.from={support address}
com.sun.mail.util.logging.MailHandler.level=WARNING
com.sun.mail.util.logging.MailHandler.verify=local
com.sun.mail.util.logging.MailHandler.subject=Application Error
com.sun.mail.util.logging.MailHandler.formatter=java.util.logging.SimpleFormatter

我使用以下方法构建类:
javac -cp $AS_INSTALL/glassfish/modules/javax.mail.jar:$AS_INSTALL/install/lib/external/jaxb/activation.jar:. MyClass.java

然后我使用以下方法运行程序:
java -cp $AS_INSTALL/glassfish/modules/javax.mail.jar:$AS_INSTALL/install/lib/external/jaxb/activation.jar:. -Djava.util.logging.config.file=logging.properties MyClass

这会导致以下错误:
Sep 22, 2011 4:19:25 PM MyClass main
SEVERE: This is a test
java.util.logging.ErrorManager: 3: SEVERE: no object DCH for MIME type multipart/mixed;
boundary="----=_Part_1_26867996.1316722766145"
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
boundary="----=_Part_1_26867996.1316722766145"
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:877)
at javax.activation.DataHandler.writeTo(DataHandler.java:302)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1476)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1772)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1748)
at com.sun.mail.util.logging.MailHandler.toRawString(MailHandler.java:2196)
at com.sun.mail.util.logging.MailHandler.send(MailHandler.java:1597)
at com.sun.mail.util.logging.MailHandler.close(MailHandler.java:552)
at java.util.logging.LogManager.resetLogger(LogManager.java:693)
at java.util.logging.LogManager.reset(LogManager.java:676)
at java.util.logging.LogManager$Cleaner.run(LogManager.java:221)

javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
boundary="----=_Part_1_26867996.1316722766145"
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1141)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at com.sun.mail.util.logging.MailHandler.send(MailHandler.java:1594)
at com.sun.mail.util.logging.MailHandler.close(MailHandler.java:552)
at java.util.logging.LogManager.resetLogger(LogManager.java:693)
at java.util.logging.LogManager.reset(LogManager.java:676)
at java.util.logging.LogManager$Cleaner.run(LogManager.java:221)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
boundary="----=_Part_1_26867996.1316722766145"
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:877)
at javax.activation.DataHandler.writeTo(DataHandler.java:302)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1476)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1772)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1099)
... 7 more

我已经验证我的 javax.mail.jar 文件包含多部分处理程序:
unzip -l $AS_INSTALL/glassfish/modules/javax.mail.jar | grep multipart
2617 01-14-2011 15:37 com/sun/mail/handlers/multipart_mixed.class

我什至在启用了激活调试的情况下运行了该程序。这向我展示了以下相关部分:
parse: multipart/*;;            x-java-content-handler=com.sun.mail.handlers.multipart_mixed; x-java-fallback-entry=true
Type: multipart/*
Command: content-handler, Class: com.sun.mail.handlers.multipart_mixed

MailcapCommandMap: createDataContentHandler for multipart/mixed
search DB #1
search DB #2
search fallback DB #1
got content-handler
class com.sun.mail.handlers.multipart_mixed
Can't load DCH com.sun.mail.handlers.multipart_mixed; Exception: java.lang.ClassNotFoundException: com/sun/mail/handlers/multipart_mixed

我什至得到了上述文本/纯文本的副本。
MailcapCommandMap: createDataContentHandler for text/plain
search DB #1
got content-handler
class com.sun.mail.handlers.text_plain
Can't load DCH com.sun.mail.handlers.text_plain; Exception: java.lang.ClassNotFoundException: com/sun/mail/handlers/text_plain

我在这里缺少什么?

谢谢,
史蒂夫

最佳答案

在发送消息之前添加这些:

MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
CommandMap.setDefaultCommandMap(mc);

我在我的 Android 应用程序中遇到了问题,并且可以正常工作。

关于logging - JavaMail 的 DCH 类错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7521027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com