// 获取公共数据 public Map<String, Object> getCommonData() { Map<String, Object> commonData = new HashMap<String, Object>(); ServletContext servletContext = JFinal.me().getServletContext(); commonData.put("base", servletContext.getContextPath()); commonData.put("systemConfig", SystemConfigUtil.getSystemConfig()); return commonData; }
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; } }
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(); } }
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; }