1 package info.magnolia.cms.mail.templates.impl; 2 3 import java.io.BufferedReader ; 4 import java.io.FileReader ; 5 import java.io.StringWriter ; 6 import java.net.URL ; 7 import java.util.Map ; 8 9 import javax.mail.Session ; 10 11 import org.apache.velocity.VelocityContext; 12 import org.apache.velocity.app.Velocity; 13 14 15 19 public class VelocityEmail extends HtmlEmail { 20 21 static { 22 try { 23 Velocity.init(); 24 } 25 catch (Exception e) { 26 log.error(e.getMessage(), e); 27 } 28 } 29 30 public VelocityEmail(Session _session) throws Exception { 31 super(_session); 32 } 33 34 public void setBodyFromResourceFile(String resourceFile, Map _map) throws Exception { 35 VelocityContext context = new VelocityContext(_map); 36 URL url = this.getClass().getResource("/" + resourceFile); 37 log.info("This is the url:" + url); 38 BufferedReader br = new BufferedReader (new FileReader (url.getFile())); 39 StringWriter w = new StringWriter (); 40 Velocity.evaluate(context, w, "email", br); 41 super.setBody(w.toString(), _map); 42 } 43 } 44 | Popular Tags |