Here is what we've done at http://www.blobcom.com for various projects:

We are using freemarker as template language and added a number of
easy-to-use features around it:

 - Automatic template handling
   - All templates are located in the same folder and can be loaded with a
method: setTemplateName(String name);
   - Emails by default uses the same locale as the incoming user for the
web-request has (if the email is sent as a part of a web-request)
   - Emails are send by a cron-job (build inside our framework). That sends
emails every 5 seconds.
   - Properties for the email are added with method: setProperty(String
key,Object value);
   - The email is stored in the database with status marks, so that we can
track status.

Freemarker advantages:
 - including other files is easy. (header / footer).
 - supports localization
 - Doesn't require jsp engine


This basically means that sending an email is as easy as:

Email email = new Email();
email.setTemplateName("Example"); (Loads:
/WEB-INF/view/mail/template/Example.ftl)
email.setFrom("exam...@example.com");
email.setTo("t...@example.com");
email.setProperty("Name","ExampleName");
email.setSubject("Just an example");
email.addAttachment(new File("c://example/bla.doc"); //We generate a
temporary file and use that. (Not absolute paths).
email.send();

Morten Matras


2010/5/25 Grzegorz Krugły <g...@karko.net>

> We have been considering this also not too long ago.
> It is possible to include a JSP using a custom HttpServletResponse so
> your app server's engine is used and there are standalone JSP engines
> but both these solutions seemed kludgy (capturing an include is not
> straightforward and adding a second JSP engine just to manipulate
> strings is overkill).
> There are also numerous templating engines, we liked StringTemplate
> (http://www.stringtemplate.org/) for instance.
>
> But in the end, we sticked to rolling out our own "engine". The code for
> it is as simple as this
>
>     /**
>      * @param fields - if param's key begins with _ it is replaced in
> the first pass, so it can contain ${} references to params replaced in
> second pass
>      */
>     private String fillInTemplate(String tmpl, Map<String, String>
> fields) {
>         for (int pass = 1; pass <= 2; pass++) {
>             for (String field : fields.keySet()) {
>                 if (field.startsWith("_") || pass == 2) {
>                     tmpl = tmpl.replace("${" + (field.startsWith("_") ?
> field.substring(1) : field) + "}", fields.get(field) != null ?
> fields.get(field) : "");
>                 }
>             }
>         }
>         return tmpl;
>     }
>
> HTH
>
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Stripes-users mailing list
> Stripes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>



-- 
 Morten Matras
 Consultant
 Blob Communication ApS
 Svendsagervej 42
 DK-5240 Odense NØ
 P: (+45) 76 6-5-4-3-2-1
 W: www.blobcom.com
 E: morten.mat...@gmail.com
------------------------------------------------------------------------------

_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to