Here's some code I use to cleanup the html before I send it and to generate an unsubscribe link. I also remove the /assets stuff from my images since that breaks the images when the web server is restarted. Html emails tend to hang around longer than web pages.


    String cleanupHtml(String s, String url, User user) {
        String html = s;
        String safeEmail = user.getEmail().replace("@", "\\$0040");

html = regexpReplace(html, "<head>", "<head>\n <BASE HREF=\"" + url + "\" />");
        html = regexpReplace(html, "/assets/ctx/[0-9a-f]+", "");
        html = regexpReplace(html, "/assets/[0-9a-f]+/ctx", "");
        html = regexpReplace(html, "<SCRIPT.*?>.*?</SCRIPT>", "");
html = regexpReplace(html, "href=\"javascript:[^\"]*\"", "href='" + url + "'"); html = regexpReplace(html, "href='javascript:[^']*'", "href='" + url + "'");
        //clear any event handlers like 'onload'
        // commented these out because it was messing with meta tags
        //html = regexpReplace(html, "on[a-zA-Z]+ *= *\"[^\"]*\"", "");
        //html = regexpReplace(html, " on[a-zA-Z]+ *= *'[^']*'", "");
        //@import url(elements.css);
        //html = regexpReplace(html, "screen.css", "presentation.css");
html = regexpReplace(html, "href=\"/liftyourgame/", "href=\"" + url);
        html = regexpReplace(html, "href=\"\\./", "href=\"" + url);
        html = regexpReplace(html, "src=\"\\./", "src=\"" + url);
        html = regexpReplace(html, "src=\"/liftyourgame/", "src=\"" + url);
        html = regexpReplace(html, "</html>.*", "</html>");
        html = regexpReplace(html, "\\[if IE][^\\[]*\\[endif]", "");

html = regexpReplace(html, "</div> <!-- footer -->", "<br/>You are subscribed as <b>" + user.getEmail() + "</b> <a href='" + url + "unsubscribe/" + safeEmail + "'>Unsubscribe</a></div> <!-- footer -->");

        html = regexpReplace(html, "<!--[^-]*-->", "");

        return html;
    }


Regards,

Greg.

On 15/12/11 09:15, Norman Franke wrote:
That's what I do, and it works fine. Make an HTTP request to render the page and include that HTML in the email. Seems a bit unclean, but it does work. One does have to be careful about session state, though. Sending a request from the server to itself will not preserve the user's session without some extra work.

Norman Franke
Answering Service for Directors, Inc.
www.myasd.com



On Dec 14, 2011, at 4:58 PM, trsvax wrote:

I would just build a Tapestry page and call it like a web service from your email code and put what it returns in the email. It should not be any more
complicated than that. If you want it to say

Dear Barry

then make the url /email?dear=Barry

and the tml

Dear ${dear}

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Generating-HTML-email-content-with-Tapestry-tp5075717p5075807.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org






---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to