/** * @param receivers * @param subject * @param content * @return true or false indicating whether the email was delivered successfully * @throws IOException */ public boolean sendMail(List<String> receivers, String subject, String content) { return sendMail(receivers, subject, content, true); }
private boolean sendTestEmail(MailService mailservice) { List<String> receivers = new ArrayList<String>(1); receivers.add("foobar@foobar.com"); return mailservice.sendMail(receivers, "A test email from Kylin", "Hello!"); } }
private void doSendMail(KylinConfig kylinConfig, List<String> users, Pair<String, String> email) { if (email == null) { logger.warn("no need to send email, content is null"); return; } logger.info("prepare to send email to:{}", users); logger.info("job name:{}", getName()); logger.info("submitter:{}", getSubmitter()); logger.info("notify list:{}", users); new MailService(kylinConfig).sendMail(users, email.getFirst(), email.getSecond()); }
protected void handleMetadataPersistException(ExecutableContext context, Throwable exception) { final String[] adminDls = context.getConfig().getAdminDls(); if (adminDls == null || adminDls.length < 1) { logger.warn(NO_NEED_TO_SEND_EMAIL_USER_LIST_IS_EMPTY); return; } List<String> users = Lists.newArrayList(adminDls); Map<String, Object> dataMap = Maps.newHashMap(); dataMap.put("job_name", getName()); dataMap.put("env_name", context.getConfig().getDeployEnv()); dataMap.put(SUBMITTER, StringUtil.noBlank(getSubmitter(), "missing submitter")); dataMap.put("job_engine", MailNotificationUtil.getLocalHostName()); dataMap.put("error_log", Matcher.quoteReplacement(StringUtil.noBlank(exception.getMessage(), "no error message"))); String content = MailNotificationUtil.getMailContent(MailNotificationUtil.METADATA_PERSIST_FAIL, dataMap); String title = MailNotificationUtil.getMailTitle("METADATA PERSIST", "FAIL", context.getConfig().getDeployEnv()); new MailService(context.getConfig()).sendMail(users, title, content); }
private boolean sendTestEmail(MailService mailservice) { List<String> receivers = new ArrayList<String>(1); receivers.add("foobar@foobar.com"); try { return mailservice.sendMail(receivers, "A test email from Kylin", "Hello!"); } catch (IOException e) { e.printStackTrace(); } return false; } }
protected final void notifyUserStatusChange(ExecutableState state) { try { List<String> users = Lists.newArrayList(); users.addAll(getNotifyList()); final String adminDls = KylinConfig.getInstanceFromEnv().getAdminDls(); if (null != adminDls) { for (String adminDl : adminDls.split(",")) { users.add(adminDl); } } if (users.isEmpty()) { return; } final Pair<String, String> email = formatNotifications(state); if (email == null) { return; } logger.info("prepare to send email to:" + users); logger.info("job name:" + getName()); logger.info("submitter:" + getSubmitter()); logger.info("notify list:" + users); new MailService().sendMail(users, email.getLeft(), email.getRight()); } catch (Exception e) { logger.error(e.getLocalizedMessage(), e); } }
/** * @param receivers * @param subject * @param content * @return true or false indicating whether the email was delivered successfully * @throws IOException */ public boolean sendMail(List<String> receivers, String subject, String content) { return sendMail(receivers, subject, content, true); }
@Controller @RequestMapping("/errorEncountered.htm") public class ErrorHandlerController { private MailService mailService; @RequestMapping(method = RequestMethod.GET) public String handleGet(HttpServletRequest request) { // The Servlet spec guarantees this attribute will be available Throwable exception = (Throwable) request .getAttribute("javax.servlet.error.exception"); . . . mailService.sendMail(); } } }
class JavaMailSender { @Autowired private MailService mailService; private void methodAsClosure(MailMessageBuilder builder) { builder.to(Arrays.asList("purno998@gmail.com")); builder.subject("Mail Subject"); builder.body("this is a message body"); } void sendMail() { MethodClosure closure = new MethodClosure(this, "methodAsClosure"); mailService.sendMail(closure); } }
private void sendMail(List<String> receivers, String title, String content) { final MailService mailService = new MailService(KylinConfig.getInstanceFromEnv()); mailService.sendMail(receivers, title, content, false); }
private void doSendMail(KylinConfig kylinConfig, List<String> users, Pair<String, String> email) { if (email == null) { logger.warn("no need to send email, content is null"); return; } logger.info("prepare to send email to:{}", users); logger.info("job name:{}", getName()); logger.info("submitter:{}", getSubmitter()); logger.info("notify list:{}", users); new MailService(kylinConfig).sendMail(users, email.getFirst(), email.getSecond()); }
@Service public class EmailAsyncService { ... @Autowired private MailService mailService; @Async public void sendEmail(User user, String email) { if (!user.getEmail().equals(email)) { user.setEmailTemp(email); Map map = new HashMap(); map.put("name", user.getName() + " " + user.getSurname()); map.put("url", "http://activationLink"); mailService.sendMail(map, "email-activation"); } } }
protected final void notifyUserStatusChange(ExecutableState state) { try { List<String> users = Lists.newArrayList(); users.addAll(getNotifyList()); final String adminDls = KylinConfig.getInstanceFromEnv().getAdminDls(); if (null != adminDls) { for (String adminDl : adminDls.split(",")) { users.add(adminDl); } } if (users.isEmpty()) { return; } final Pair<String, String> email = formatNotifications(state); if (email == null) { return; } logger.info("prepare to send email to:" + users); logger.info("job name:" + getName()); logger.info("submitter:" + getSubmitter()); logger.info("notify list:" + users); new MailService().sendMail(users, email.getLeft(), email.getRight()); } catch (Exception e) { logger.error(e.getLocalizedMessage(), e); } }
protected void handleMetadataPersistException(ExecutableContext context, Throwable exception) { final String[] adminDls = context.getConfig().getAdminDls(); if (adminDls == null || adminDls.length < 1) { logger.warn(NO_NEED_TO_SEND_EMAIL_USER_LIST_IS_EMPTY); return; } List<String> users = Lists.newArrayList(adminDls); Map<String, Object> dataMap = Maps.newHashMap(); dataMap.put("job_name", getName()); dataMap.put("env_name", context.getConfig().getDeployEnv()); dataMap.put(SUBMITTER, StringUtil.noBlank(getSubmitter(), "missing submitter")); dataMap.put("job_engine", MailNotificationUtil.getLocalHostName()); dataMap.put("error_log", Matcher.quoteReplacement(StringUtil.noBlank(exception.getMessage(), "no error message"))); String content = MailNotificationUtil.getMailContent(MailNotificationUtil.METADATA_PERSIST_FAIL, dataMap); String title = MailNotificationUtil.getMailTitle("METADATA PERSIST", "FAIL", context.getConfig().getDeployEnv()); new MailService(context.getConfig()).sendMail(users, title, content); }
@Component public class MailScheduleTimer extends TimerTask{ @Autowired MailService mailService; @Autowired UserAccountRepository userAccountRepository; Logger logger = Logger.getLogger(MailScheduleTimer.class); @Override public void run() { try { List<UserAccount> userAccounts = userAccountRepository .getUserAccounts(); for (UserAccount userAccount : userAccounts) { if (userAccount.getUserRole().getName() .equals(RolesConstant.USER_ROLE) && userAccount.getMailStatus().equals("N")) { mailService.sendMail(userAccount.getName(), userAccount.getUserId(), "profile", userAccount.getName()); userAccount.setMailStatus("Y"); userAccountRepository.saveAndFlush(userAccount); } } } catch (Exception e) { logger.error("Unable to Send Mail..." + e); } } }