public static void main(String[] args) throws IOException {
   StringTemplateResourceLoader strl = new StringTemplateResourceLoader();
   Configuration cfg = Configuration.defaultConfiguration();
   String inputStr = "Hello ${myName}";
   GroupTemplate gt = new GroupTemplate(strl, cfg);
   Template t = gt.getTemplate(inputStr);
   t.binding("myName", "Lost World vsked is here");
   String outStr = t.render();
   System.out.println(outStr);
 }
  public BeetlActionResult() {

    try {

      Configuration cfg = Configuration.defaultConfiguration();
      WebAppResourceLoader resourceLoader = new WebAppResourceLoader();
      groupTemplate = new GroupTemplate(resourceLoader, cfg);

    } catch (IOException e) {
      throw new RuntimeException("加载GroupTemplate失败", e);
    }
  }
Beispiel #3
0
  public void sendSmtpTestMail(
      String smtpFromMail,
      String smtpHost,
      Integer smtpPort,
      String smtpUsername,
      String smtpPassword,
      String toMail) {
    SystemConfig systemConfig = SystemConfigUtil.getSystemConfig();
    MailConfig mailConfig = TemplateConfigUtil.getMailConfig(MailConfig.SMTP_TEST);
    String subject = mailConfig.getSubject();
    String templateFilePath = mailConfig.getTemplateFilePath();
    try {
      email = new HtmlEmail();
      email.setHostName(systemConfig.getSmtpHost());
      email.setSmtpPort(systemConfig.getSmtpPort());
      email.setAuthenticator(
          new DefaultAuthenticator(systemConfig.getSmtpUsername(), systemConfig.getSmtpPassword()));
      email.setSSLOnConnect(true);

      WebAppResourceLoader resourceLoader = new WebAppResourceLoader();
      Configuration cfg = Configuration.defaultConfiguration();
      GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
      Template template = gt.getTemplate(templateFilePath);
      template.binding("systemConfig", systemConfig);
      String text = template.render();

      email.setFrom(
          MimeUtility.encodeWord(systemConfig.getShopName())
              + " <"
              + systemConfig.getSmtpFromMail()
              + ">");
      email.setSubject(subject);
      email.setMsg(text);
      email.addTo(toMail);
      email.send();

    } catch (EmailException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Beispiel #4
0
  public boolean sendMail(
      String subject, String templateFilePath, Map<String, Object> data, String toMail) {
    boolean isSend = false;
    try {
      SystemConfig systemConfig = SystemConfigUtil.getSystemConfig();

      email = new HtmlEmail();
      email.setHostName(systemConfig.getSmtpHost());
      email.setSmtpPort(systemConfig.getSmtpPort());
      email.setAuthenticator(
          new DefaultAuthenticator(systemConfig.getSmtpUsername(), systemConfig.getSmtpPassword()));
      email.setSSLOnConnect(true);

      WebAppResourceLoader resourceLoader = new WebAppResourceLoader();
      Configuration cfg = Configuration.defaultConfiguration();
      GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
      Template template = gt.getTemplate(templateFilePath);
      template.binding(data);
      String text = template.render();

      email.setFrom(
          MimeUtility.encodeWord(systemConfig.getShopName())
              + " <"
              + systemConfig.getSmtpFromMail()
              + ">");
      email.setSubject(subject);
      email.setMsg(text);
      email.addTo(toMail);
      email.send();
      isSend = true;
    } catch (EmailException e) {
      e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return isSend;
  }