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()); }
MailService mailer = new MailService("from@mydomain.com","to@domain.com","Subject","TextBody", "<b>HtmlBody</b>", (Attachment) null); try { mailer.sendAuthenticated(); } catch (Exception e) { Log.e(AskTingTing.APP, "Failed sending email.", 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); }
@Test public void testSendEmail() throws IOException { KylinConfig config = KylinConfig.getInstanceFromEnv(); MailService mailservice = new MailService(config); boolean sent = sendTestEmail(mailservice); assert sent; System.setProperty("kylin.job.notification-enabled", "false"); // set kylin.job.notification-enabled=false, and run again, this time should be no mail delivered mailservice = new MailService(config); sent = sendTestEmail(mailservice); assert !sent; }
private final Condition flushCondition = flushLock.newCondition(); MailService mailService = new MailService(); consumerExecutor.submit(() -> { LOGGER.info("{} sending {} mails", Thread.currentThread(), toFLush.size()); mailService.sendEmails(toFLush); });
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!"); } }
@Test public void testSendEmail() throws IOException { KylinConfig config = KylinConfig.getInstanceFromEnv(); MailService mailservice = new MailService(config); boolean sent = sendTestEmail(mailservice); assert sent; // set mail.enabled=false, and run again, this time should be no mail delviered config.setProperty(KylinConfig.MAIL_ENABLED, "false"); mailservice = new MailService(config); sent = sendTestEmail(mailservice); assert !sent; }
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; } }
public class MyExample { private static final Logger logger; private static final int STATIC_VAR = 1; private final WebService service; private final String property; private final MailService mail; @Autowired public MyExample(WebService service, @Value("${my.property}") String property) { this.service = service; this.property = property; mail = new MailService(); } }
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); }
@Configuration public class TestConfiguration { //this is the real mail service @Bean public MailService mailService() { return new MailService(); //or whatever other bean creation logic you are using } //whatever else } @Configuration @Profile("mockMail") public class MockMailServiceConfig { @Bean @Primary public MailService mockMailService() { return mock(MailService.class); } }
private void sendMail(List<String> receivers, String title, String content) { final MailService mailService = new MailService(KylinConfig.getInstanceFromEnv()); mailService.sendMail(receivers, title, content, false); }
@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(); } } }
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()); }
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); } }
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); } }
@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 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); }