The way I've solved this before is by printing a JSP to a String and then sending that String as the body of the email. This is easy if you're in a webapp already (which I was). If you're not in a webapp, I don't recommend it.
Here's a stackoverflow answer on how to do it. And here's some sample code I use:
public static String generateEmailBodyAsString(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, ServletContext servletContext) throws Exception {
StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
final ServletOutputStream outputStream = new ServletOutputStream() {
@Override
public void write(int b) throws IOException {
printWriter.write(b);
}
};
HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper(httpServletResponse) {
@Override
public PrintWriter getWriter() throws IOException {
return printWriter;
}
@Override
public ServletOutputStream getOutputStream() throws IOException {
return outputStream;
}
};
httpServletRequest.setAttribute("youCanAccessThisAsAVariableInYourJsp", "some value"); //in your jsp refer to it as ${youCanAccessThisAsAVariableInYourJsp}
servletContext.getRequestDispatcher("/emailBody.jsp").include(httpServletRequest, wrapper);
return stringWriter.toString();
}
(Note: This code compiles but I've modified it to hide specifics of my app so it may not work for you at runtime. If you have any issues add a comment and I'll try to help)