The most compact way to generate nicely formatted e-mails using a mapping in PO is to use a XSLT transformation. However, it can be done with a java UDF as well. Here is an approach...

Using XSLT for generating HTML has some drawbacks. First, it requires an external development tool and some xslt knowledge. Furthermore, to use the XSL mapping in combination with another mapping to fill the all fields of the mail package message, an intermediate message definition is required in order to sequentially execute the mappings (one XSLt for the content and one for the other taget fields)

Using a UDF (java) makes the mapping easier to comprehend as the content is now generated from a single UDF placed in the standard graphical mapping tool. Hence, only one (graphical) mapping is required. However, generating HTML in java requires more code lines than using a style sheet transformation! Using an html generator library makes this easier though...

In this example the library is taken from artho software. The classes need to packaged into a zip (which can be downloaded here: and imported as an archive into the ESR of PO:

import html generator library 

After import the archive can be used to in an UDF to generate HTML content. Just refer to the html package at the import section of the UDF.

UDF for HTML content

Some code snippets are shown below. The UDF can be used as single value function or as a queue/context function.

    Tag html = new Tag("html");
    Tag head = new Tag("head", "meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"");
    Tag style= new Tag("style", "type=\"text/css\"");
    style.add("body { font-family:Tahoma, Geneva, sans-serif; font-size: 10pt; } h1 { color:#213084; background-color:#eff2b6; text-width: bold; font-size:14pt; } table.lines th { color:#213084; background-color:#eff2b6; border-width: 1px 1px 1px 1px; border-style: solid none solid none; border-color: black; text-align: left; font-size: 10pt; } table.lines td { border-width: 1px 1px 1px 1px; border-style: none none solid none; border-color: black; font-size: 10pt; vertical-align: middle; } table { border-spacing:0 } table.nolines td { border-width: 0 0 0 0; padding: 0 0 0 0; border-style: none none none none; font-size: 10pt; vertical-align: top; }");
    Tag title = new Tag("title", "id=\"subject\"");
    title.add("My email title");
    Tag body = new Tag("body");
    Tag h1 = new Tag("h1");
    h1.add("E-Mail Heading");
    // table with rows 
    Tag table = new Tag("table", "class = nolines");
    // row 1, 
    Tag tr = new Tag("tr");
    Tag cell = new Tag("td", "style=\"width: 175px;\"");
    cell.add("Label row 1");
    cell =  new Tag("td", "colspan=\"2\"");
    cell.add(":  " + var1);

    // finish the page
    return html.toString();