简体   繁体   English

JavaMail无法显示html正文

[英]JavaMail not able to display html body

I am having trouble getting the SimpleClient sample app that comes with JavaMail, to work. 我无法使JavaMail随附的SimpleClient示例应用程序正常工作。 Emails with plain text bodies display just fine in the viewer. 带有纯文本正文的电子邮件在查看器中显示良好。 But for html bodies it fails to find the appropriate content viewer. 但是对于html正文,它找不到合适的内容查看器。 It's the line Object bean = dh.getBean(ci); 这行是Object bean = dh.getBean(ci); at around line 205 in MessageViewer.getBodyComponent() , that results in bean getting assigned a null pointer, that causes the problem. MessageViewer.getBodyComponent()第205行附近,这导致bean被分配了空指针,从而导致了问题。

Earlier today I asked for help finding the source for javax.activation, hoping I could figure out the problem. 今天早些时候,我寻求帮助来找到javax.activation的源代码,希望能找出问题所在。 But unfortunately when I step into that code, it goes to the wrong line in the source file, meaning I can't for the life of me figure out what is going wrong! 但是不幸的是,当我进入该代码时,它到达了源文件中的错误行,这意味着我无法终生弄清楚出了什么问题!

[I know nothing about Java Beans; [我对Java Bean一无所知; this could be my problem. 这可能是我的问题。 Please feel free to recommend that I do some learning about this technology :-) I haven't yet, for the simple reason that I have other things to do with my time. 请随意建议我对这项技术进行一些学习:-)我还没有,原因很简单,我与自己的时间有其他关系。 If, however, it's necessary, then I'll do it :-) ] 但是,如果有必要,那么我会做:-)]

Has anyone else had this problem and how did you solve it? 还有其他人有这个问题吗,您如何解决呢?

The JavaBeans Activation Framework (JAF) has been included in the JDK since JDK 1.6. 自JDK 1.6起,JavaBeans激活框架(JAF)已包含在JDK中。 You can find the source code in the OpenJDK repository for recent versions. 您可以在OpenJDK存储库中找到最新版本的源代码。

When JAF was included in the JDK, none of the sample viewers were included. 当JAF包含在JDK中时,没有包含任何示例查看器。 You can download the standalone JAF 1.1.1 release , which includes the sample viewers, and include it in your CLASSPATH. 您可以下载独立的JAF 1.1.1版本 ,其中包括示例查看器,并将其包含在CLASSPATH中。

And, just to be really clear, these are sample viewers, perhaps good enough for the JavaMail sample programs , but not good for much else. 而且,非常清楚地说,这些是示例查看器,对于JavaMail示例程序来说可能已经足够好了,但对于其他许多方面却没有什么帮助。 In particular, the text viewer displays all text as if it were plain text. 特别是,文本查看器将所有文本显示为纯文本。 You could get the same effect by changing the simple.mailcap file included with the SimpleClient to use "text/*". 通过将SimpleClient附带的simple.mailcap文件更改为使用“ text / *”,可以达到相同的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM