tapestry mail freemarker的使用

1)使用方式

@Inject
@Path("context:/templates/report.ftl")
private Asset template;
       
@Inject
private MailService<Email> mailService;
       
@Inject @FreeMarker
private TemplateService _templateService;

public String getPassengerList() {
    OutputStream os = new ByteArrayOutputStream();
    Map<String, String> parameterMap = new HashMap<String, String>();
    parameterMap.put("name", "xxxx");
    parameterMap.put("content", "hello world is the first program you write!");
    _templateService.mergeDataWithResource(template.getResource(), os, parameterMap);
    return os.toString();
}
    
void onSendMail() {
   MailMessageHeaders headers = new MailMessageHeaders();
   headers.addTo("[email protected]");
   headers.addBcc("[email protected]");
   headers.addCc("[email protected]");
   headers.setSubject("just for test only");
   mailService.sendPlainTextMail(headers, getPassengerList());
}


1)在context.xml中配置mail session

<Resource name="mail/session"
              auth="Container"
              type="javax.mail.Session"
              factory="org.apache.naming.factory.MailSessionFactory"
              mail.transport.protocol="smtp"
              mail.smtp.host="smtp.xxxxx.xx"
              mail.smtp.port="25"
              mail.smtp.auth="true"
              mail.smtp.user="[email protected]"
              password="yyyyy"
              mail.from="[email protected]"
              mail.debug="false"
              />


你可能感兴趣的:(tapestry mail freemarker的使用)