简体   繁体   中英

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. My goal is to send the contents of an xml file formatted by an xsl file as the message of the e-mail. Is this possible?

I know that the following code can be used to send a string containing 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? If this is so, then the same must apply to xml and 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.

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.

Thank you.

It's true that most email clients will not process 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. Sometimes this is done by preprocessing the document with XSLT.

If you want to take this route, I suggest you look at the Saxon XSLT processor to preprocess your XML document.

Another option to handle this problem would be something like Emogrifier , Premailer , or even this SO Question . Which processes a CSS and HTML into one inline-styled email-safe document.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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