@Test public void testSendMail() throws SQLException { mockDB(SurveillerConstants.SUBSCRIPTION_TYPE_EMAIL, "ut@tmo.com"); MockUp <Transport>mailMock = new MockUp<Transport>() { @Mock public void send(Message message) { } }; List <HealthCheckVO> hcs = new ArrayList<HealthCheckVO>(); HealthCheckVO hc = getHealthCheckVO(); hcs.add(hc); hc.setFailureStatusMessage("Failed message"); MailSenderUtil.sendMailForHealthCheckVos(hcs); dbMock.tearDown(); mailMock.tearDown(); }
public static void sendMail(String messageText, String toMail, String subject){ Properties props = new Properties(); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_IP)); props.put("mail.smtp.port", propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_PORT)); Session session = null; String mailAuthUserName = propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_USERNAME); String mailAuthPassword = propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_PASSWORD); if (mailAuthUserName != null && mailAuthUserName.length() > 0 && mailAuthPassword != null && mailAuthPassword.length() > 0) { props.put("mail.smtp.auth", "true"); Authenticator auth = new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(mailAuthUserName, mailAuthPassword); } }; session = Session.getDefaultInstance(props, auth); } else { props.put("mail.smtp.auth", "false"); session = Session.getInstance(props); } try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(propertyUtil.getValue(SurveillerConstants.MAIL_FROM_ADDRESS) )); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toMail)); message.setSubject(subject); message.setText(messageText); Transport.send(message); } catch (MessagingException me) { logger.error("Error in Mail Sending: " + me); throw new RuntimeException(me.getMessage()); } logger.debug("Mail Sent to: " + toMail); }
MailSenderUtil { public static void sendMail(String messageText, String toMail, String subject){ Properties props = new Properties(); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_IP)); props.put("mail.smtp.port", propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_PORT)); Session session = null; String mailAuthUserName = propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_USERNAME); String mailAuthPassword = propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_PASSWORD); if (mailAuthUserName != null && mailAuthUserName.length() > 0 && mailAuthPassword != null && mailAuthPassword.length() > 0) { props.put("mail.smtp.auth", "true"); Authenticator auth = new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(mailAuthUserName, mailAuthPassword); } }; session = Session.getDefaultInstance(props, auth); } else { props.put("mail.smtp.auth", "false"); session = Session.getInstance(props); } try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(propertyUtil.getValue(SurveillerConstants.MAIL_FROM_ADDRESS) )); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toMail)); message.setSubject(subject); message.setText(messageText); Transport.send(message); } catch (MessagingException me) { logger.error("Error in Mail Sending: " + me); throw new RuntimeException(me.getMessage()); } logger.debug("Mail Sent to: " + toMail); } }
MailSenderUtil { public static void sendMail(String messageText, String toMail, String subject){ Properties props = new Properties(); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_IP)); props.put("mail.smtp.port", propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_PORT)); Session session = null; String mailAuthUserName = propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_USERNAME); String mailAuthPassword = propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_PASSWORD); if (mailAuthUserName != null && mailAuthUserName.length() > 0 && mailAuthPassword != null && mailAuthPassword.length() > 0) { props.put("mail.smtp.auth", "true"); Authenticator auth = new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(mailAuthUserName, mailAuthPassword); } }; session = Session.getDefaultInstance(props, auth); } else { props.put("mail.smtp.auth", "false"); session = Session.getInstance(props); } try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(propertyUtil.getValue(SurveillerConstants.MAIL_FROM_ADDRESS) )); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toMail)); message.setSubject(subject); message.setText(messageText); Transport.send(message); } catch (MessagingException me) { logger.error("Error in Mail Sending: " + me); throw new RuntimeException(me.getMessage()); } logger.debug("Mail Sent to: " + toMail); } private  MailSenderUtil(); }
MailSenderUtil { public static void sendMail(String messageText, String toMail, String subject){ Properties props = new Properties(); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_IP)); props.put("mail.smtp.port", propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_PORT)); Session session = null; String mailAuthUserName = propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_USERNAME); String mailAuthPassword = propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_PASSWORD); if (mailAuthUserName != null && mailAuthUserName.length() > 0 && mailAuthPassword != null && mailAuthPassword.length() > 0) { props.put("mail.smtp.auth", "true"); Authenticator auth = new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(mailAuthUserName, mailAuthPassword); } }; session = Session.getDefaultInstance(props, auth); } else { props.put("mail.smtp.auth", "false"); session = Session.getInstance(props); } try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(propertyUtil.getValue(SurveillerConstants.MAIL_FROM_ADDRESS) )); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toMail)); message.setSubject(subject); message.setText(messageText); Transport.send(message); } catch (MessagingException me) { logger.error("Error in Mail Sending: " + me); throw new RuntimeException(me.getMessage()); } logger.debug("Mail Sent to: " + toMail); } private  MailSenderUtil(); static void sendMailForHealthCheckVos(List<HealthCheckVO> stsChgList); static void sendMessageToSlackChannel(HealthCheckVO hVo, String slackChannelName, String subject); static void sendMail(String messageText, String toMail, String subject); }
MailSenderUtil { public static void sendMail(String messageText, String toMail, String subject){ Properties props = new Properties(); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_IP)); props.put("mail.smtp.port", propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_PORT)); Session session = null; String mailAuthUserName = propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_USERNAME); String mailAuthPassword = propertyUtil.getValue(SurveillerConstants.MAIL_SERVER_PASSWORD); if (mailAuthUserName != null && mailAuthUserName.length() > 0 && mailAuthPassword != null && mailAuthPassword.length() > 0) { props.put("mail.smtp.auth", "true"); Authenticator auth = new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(mailAuthUserName, mailAuthPassword); } }; session = Session.getDefaultInstance(props, auth); } else { props.put("mail.smtp.auth", "false"); session = Session.getInstance(props); } try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(propertyUtil.getValue(SurveillerConstants.MAIL_FROM_ADDRESS) )); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toMail)); message.setSubject(subject); message.setText(messageText); Transport.send(message); } catch (MessagingException me) { logger.error("Error in Mail Sending: " + me); throw new RuntimeException(me.getMessage()); } logger.debug("Mail Sent to: " + toMail); } private  MailSenderUtil(); static void sendMailForHealthCheckVos(List<HealthCheckVO> stsChgList); static void sendMessageToSlackChannel(HealthCheckVO hVo, String slackChannelName, String subject); static void sendMail(String messageText, String toMail, String subject);  }