简体   繁体   English

如何发送XSL格式的XML文件作为JavaMail电子邮件的消息

[英]How do I send an XSL formatted XML file as the message of a JavaMail e-mail

I am using JavaMail to send an e-mail. 我正在使用JavaMail发送电子邮件。 My goal is to send the contents of an xml file formatted by an xsl file as the message of the e-mail. 我的目标是发送由xsl文件格式化的xml文件的内容作为电子邮件的消息。 Is this possible? 这可能吗?

I know that the following code can be used to send a string containing html. 我知道以下代码可用于发送包含html的字符串。

message.set.Content(htmlString, "text/html");

Am I correct in my assumption that the formatting information to create a html message in an e-mail must be embedded in the html and that there is no way to connect to a css? 我的假设是正确的,即在电子邮件中创建html消息的格式信息必须嵌入html中,并且无法连接到CSS? If this is so, then the same must apply to xml and xsl. 如果是这样,则必须对xml和xsl相同。 If there is a way to join an existing xml file and an existing xsl file in the body of a JavaMail e-mail, I would be very grateful to anyone who can give me the code that makes this possible. 如果有一种方法可以将现有的xml文件和现有的xsl文件加入JavaMail电子邮件的正文中,那么我将非常感激任何能为我提供使之成为可能的代码的人。

If it is impossible, I will be happy to be informed of this and pointed in the right direction. 如果不可能,我将很高兴获悉这一情况并指出正确的方向。 I suspect that I will need to parse the xml file and convert it to a string containing html formatting. 我怀疑我将需要解析xml文件并将其转换为包含html格式的字符串。

Thank you. 谢谢。

It's true that most email clients will not process CSS. 的确,大多数电子邮件客户端不会处理CSS。 Here's a chart . 这是一张图表

As a result, it's commonplace to apply formatting by transforming the CSS-formatted HTML to an inline-style that most email clients can handle. 结果,通过将CSS格式的HTML转换为大多数电子邮件客户端可以处理的内联样式来应用格式是司空见惯的。 Sometimes this is done by preprocessing the document with XSLT. 有时,这是通过使用XSLT预处理文档来完成的。

If you want to take this route, I suggest you look at the Saxon XSLT processor to preprocess your XML document. 如果您想采用这种方法,建议您使用Saxon XSLT处理器来预处理XML文档。

Another option to handle this problem would be something like Emogrifier , Premailer , or even this SO Question . 解决此问题的另一种方法是使用EmogrifierPremailer甚至是SO Question Which processes a CSS and HTML into one inline-styled email-safe document. 它将CSS和HTML处理成一个内联样式的电子邮件安全文档。

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

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