1)使用方式java
@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("to@mail.cn"); headers.addBcc("Bcc@mail.cn"); headers.addCc("cc@mail.cn"); headers.setSubject("just for test only"); mailService.sendPlainTextMail(headers, getPassengerList()); }
1)在context.xml中配置mail sessionapache
<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="xxxxxx@xxxxxx.xx" password="yyyyy" mail.from="xxxxxx@xxxxxx.xx" mail.debug="false" />