/** * Send. * * @throws JavaMailerException the java mailer exception */ public void send() throws JavaMailerException { if (m_config.getSendmailProtocol() == null || m_config.getSendmailMessage() == null) { throw new JavaMailerException("sendmail-protocol or sendmail-message are not configured!"); } try { final SendmailProtocol sendmailProtocol = m_config.getSendmailProtocol(); final String body = m_config.getSendmailMessage().getBody(); if ("text/plain".equals(sendmailProtocol.getMessageContentType().toLowerCase())) { m_message.setText(body); } else { m_message.setContent(body, sendmailProtocol.getMessageContentType()); } } catch (final MessagingException e) { LOG.error("Java Mailer messaging exception: {}", e, e); throw new JavaMailerException("Java Mailer messaging exception: " + e, e); } send(m_message); }
/** * Send. * * @throws JavaMailerException the java mailer exception */ public void send() throws JavaMailerException { if (m_config.getSendmailProtocol() == null || m_config.getSendmailMessage() == null) { throw new JavaMailerException("sendmail-protocol or sendmail-message are not configured!"); } try { final SendmailProtocol sendmailProtocol = m_config.getSendmailProtocol(); final String body = m_config.getSendmailMessage().getBody(); if ("text/plain".equals(sendmailProtocol.getMessageContentType().toLowerCase())) { m_message.setText(body); } else { m_message.setContent(body, sendmailProtocol.getMessageContentType()); } } catch (final MessagingException e) { LOG.error("Java Mailer messaging exception: {}", e, e); throw new JavaMailerException("Java Mailer messaging exception: " + e, e); } send(m_message); }
/** * Gets the sendmail configuration. * * @param alarm the northbound alarm * @return the sendmail configuration */ protected SendmailConfig getSendmailConfig(NorthboundAlarm alarm) { SendmailMessage message = new SendmailMessage(); message.setFrom(m_emailFrom); message.setTo(m_emailTo); message.setSubject(m_emailSubjectFormat); message.setBody(m_emailBodyFormat); for (EmailFilter filter : m_destination.getFilters()) { if (filter.accepts(alarm)) { filter.update(message); continue; } } LOG.debug("getSendmailConfig: from = {}", message.getFrom()); LOG.debug("getSendmailConfig: to = {}", message.getTo()); Map<String, Object> mapping = createMapping(alarm, null); final String subject = PropertiesUtils.substitute(message.getSubject(), mapping); LOG.debug("getSendmailConfig: subject = {}", subject); message.setSubject(subject); final String body = PropertiesUtils.substitute(message.getBody(), mapping); LOG.debug("getSendmailConfig: body = {}", body); message.setBody(body); m_sendmail.setSendmailMessage(message); return m_sendmail; }
/** * Gets the sendmail configuration. * * @param alarm the northbound alarm * @return the sendmail configuration */ protected SendmailConfig getSendmailConfig(NorthboundAlarm alarm) { SendmailMessage message = new SendmailMessage(); message.setFrom(m_emailFrom); message.setTo(m_emailTo); message.setSubject(m_emailSubjectFormat); message.setBody(m_emailBodyFormat); for (EmailFilter filter : m_destination.getFilters()) { if (filter.accepts(alarm)) { filter.update(message); continue; } } LOG.debug("getSendmailConfig: from = {}", message.getFrom()); LOG.debug("getSendmailConfig: to = {}", message.getTo()); Map<String, Object> mapping = createMapping(alarm, null); final String subject = PropertiesUtils.substitute(message.getSubject(), mapping); LOG.debug("getSendmailConfig: subject = {}", subject); message.setSubject(subject); final String body = PropertiesUtils.substitute(message.getBody(), mapping); LOG.debug("getSendmailConfig: body = {}", body); message.setBody(body); m_sendmail.setSendmailMessage(message); return m_sendmail; }
/** * Instantiates a new SNMP Trap northbounder. * * @param configDao the SNMP Trap configuration DAO * @param javaMailDao the JavaMail configuration DAO * @param destinationName the destination name */ public EmailNorthbounder(EmailNorthbounderConfigDao configDao, JavaMailConfigurationDao javaMailDao, String destinationName) { super(NBI_NAME + ":" + destinationName); m_configDao = configDao; m_destination = configDao.getConfig().getEmailDestination(destinationName); // Creating a local copy of the SendmailConfig object, to avoid potential thread contention issues. try { final SendmailConfig sendmail = javaMailDao.getSendMailConfig(destinationName); if (sendmail != null) { final String sendmailText = JaxbUtils.marshal(sendmail); m_sendmail = JaxbUtils.unmarshal(SendmailConfig.class, sendmailText); } } catch (Exception e) { LOG.error("Can't create a copy of the SendmailConfig object named {}.", destinationName, e); } // Saving a local copy of the templates, as they will be overridden every time a new email has to be sent. if (m_sendmail != null && m_sendmail.getSendmailMessage() != null) { final SendmailMessage sendmailMessage = m_sendmail.getSendmailMessage(); m_emailSubjectFormat = sendmailMessage.getSubject(); m_emailBodyFormat = sendmailMessage.getBody(); m_emailFrom = sendmailMessage.getFrom(); m_emailTo = sendmailMessage.getTo(); } }
/** * Instantiates a new SNMP Trap northbounder. * * @param configDao the SNMP Trap configuration DAO * @param javaMailDao the JavaMail configuration DAO * @param destinationName the destination name */ public EmailNorthbounder(EmailNorthbounderConfigDao configDao, JavaMailConfigurationDao javaMailDao, String destinationName) { super(NBI_NAME + ":" + destinationName); m_configDao = configDao; m_destination = configDao.getConfig().getEmailDestination(destinationName); // Creating a local copy of the SendmailConfig object, to avoid potential thread contention issues. try { final SendmailConfig sendmail = javaMailDao.getSendMailConfig(destinationName); if (sendmail != null) { final String sendmailText = JaxbUtils.marshal(sendmail); m_sendmail = JaxbUtils.unmarshal(SendmailConfig.class, sendmailText); } } catch (Exception e) { LOG.error("Can't create a copy of the SendmailConfig object named {}.", destinationName, e); } // Saving a local copy of the templates, as they will be overridden every time a new email has to be sent. if (m_sendmail != null && m_sendmail.getSendmailMessage() != null) { final SendmailMessage sendmailMessage = m_sendmail.getSendmailMessage(); m_emailSubjectFormat = sendmailMessage.getSubject(); m_emailBodyFormat = sendmailMessage.getBody(); m_emailFrom = sendmailMessage.getFrom(); m_emailTo = sendmailMessage.getTo(); } }