@Test public void testSendMails() { String[] mails = new String[]{"qifeng.dai@baifendian.com"}; String title = "test from swordfish"; String content = "test"; MailSendUtil.sendMails(Arrays.asList(mails), title, content); }
public static boolean sendMails(Collection<String> receivers, String title, String content) { if (receivers == null) { LOGGER.error("Mail receivers is null."); return false; } receivers.removeIf((from) -> (StringUtils.isEmpty(from))); if (receivers.isEmpty()) { LOGGER.error("Mail receivers is empty."); return false; } HtmlEmail email = new HtmlEmail(); try { email.setHostName(mailServerHost); email.setSmtpPort(mailServerPort); email.setCharset("UTF-8"); for (String receiver : receivers) { email.addTo(receiver); } email.setFrom(mailSender, mailSender); email.setAuthentication(mailSender, mailPasswd); email.setSubject(title); email.setMsg(content); email.send(); return true; } catch (Throwable e) { LOGGER.error("Send email to {} failed", StringUtils.join(",", receivers), e); } return false; }
MailSendUtil { public static boolean sendMails(Collection<String> receivers, String title, String content) { if (receivers == null) { LOGGER.error("Mail receivers is null."); return false; } receivers.removeIf((from) -> (StringUtils.isEmpty(from))); if (receivers.isEmpty()) { LOGGER.error("Mail receivers is empty."); return false; } HtmlEmail email = new HtmlEmail(); try { email.setHostName(mailServerHost); email.setSmtpPort(mailServerPort); email.setCharset("UTF-8"); for (String receiver : receivers) { email.addTo(receiver); } email.setFrom(mailSender, mailSender); email.setAuthentication(mailSender, mailPasswd); email.setSubject(title); email.setMsg(content); email.send(); return true; } catch (Throwable e) { LOGGER.error("Send email to {} failed", StringUtils.join(",", receivers), e); } return false; } }
MailSendUtil { public static boolean sendMails(Collection<String> receivers, String title, String content) { if (receivers == null) { LOGGER.error("Mail receivers is null."); return false; } receivers.removeIf((from) -> (StringUtils.isEmpty(from))); if (receivers.isEmpty()) { LOGGER.error("Mail receivers is empty."); return false; } HtmlEmail email = new HtmlEmail(); try { email.setHostName(mailServerHost); email.setSmtpPort(mailServerPort); email.setCharset("UTF-8"); for (String receiver : receivers) { email.addTo(receiver); } email.setFrom(mailSender, mailSender); email.setAuthentication(mailSender, mailPasswd); email.setSubject(title); email.setMsg(content); email.send(); return true; } catch (Throwable e) { LOGGER.error("Send email to {} failed", StringUtils.join(",", receivers), e); } return false; }  }
MailSendUtil { public static boolean sendMails(Collection<String> receivers, String title, String content) { if (receivers == null) { LOGGER.error("Mail receivers is null."); return false; } receivers.removeIf((from) -> (StringUtils.isEmpty(from))); if (receivers.isEmpty()) { LOGGER.error("Mail receivers is empty."); return false; } HtmlEmail email = new HtmlEmail(); try { email.setHostName(mailServerHost); email.setSmtpPort(mailServerPort); email.setCharset("UTF-8"); for (String receiver : receivers) { email.addTo(receiver); } email.setFrom(mailSender, mailSender); email.setAuthentication(mailSender, mailPasswd); email.setSubject(title); email.setMsg(content); email.send(); return true; } catch (Throwable e) { LOGGER.error("Send email to {} failed", StringUtils.join(",", receivers), e); } return false; }  static boolean sendMails(Collection<String> receivers, String title, String content); }
MailSendUtil { public static boolean sendMails(Collection<String> receivers, String title, String content) { if (receivers == null) { LOGGER.error("Mail receivers is null."); return false; } receivers.removeIf((from) -> (StringUtils.isEmpty(from))); if (receivers.isEmpty()) { LOGGER.error("Mail receivers is empty."); return false; } HtmlEmail email = new HtmlEmail(); try { email.setHostName(mailServerHost); email.setSmtpPort(mailServerPort); email.setCharset("UTF-8"); for (String receiver : receivers) { email.addTo(receiver); } email.setFrom(mailSender, mailSender); email.setAuthentication(mailSender, mailPasswd); email.setSubject(title); email.setMsg(content); email.send(); return true; } catch (Throwable e) { LOGGER.error("Send email to {} failed", StringUtils.join(",", receivers), e); } return false; }  static boolean sendMails(Collection<String> receivers, String title, String content);  }