1

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.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
patantdoh
  • 11
  • 2

1 Answers1

1

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.

Community
  • 1
  • 1
Jon W
  • 15,480
  • 6
  • 37
  • 47