Exemple #1
0
 public boolean isMailConfigComplete() {
   SystemConfig systemConfig = SystemConfigUtil.getSystemConfig();
   if (StringUtils.isEmpty(systemConfig.getSmtpFromMail())
       || StringUtils.isEmpty(systemConfig.getSmtpHost())
       || systemConfig.getSmtpPort() == null
       || StringUtils.isEmpty(systemConfig.getSmtpUsername())
       || StringUtils.isEmpty(systemConfig.getSmtpPassword())) {
     return false;
   } else {
     return true;
   }
 }
Exemple #2
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();
    }
  }
Exemple #3
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;
  }