private void mailReport(DeliveryOptions deliveryOptions, ByteArrayOutputStream outputStream) { try { JavaMailer jm = new JavaMailer(); jm.setTo(deliveryOptions.getMailTo()); jm.setSubject(deliveryOptions.getInstanceId()); jm.setMessageText("Here is your report from the OpenNMS report service."); jm.setInputStream(new ByteArrayInputStream(outputStream.toByteArray())); switch (deliveryOptions.getFormat()) { case HTML: jm.setInputStreamName(deliveryOptions.getInstanceId() + ".htm"); jm.setInputStreamContentType("text/html"); break; case PDF: jm.setInputStreamName(deliveryOptions.getInstanceId() + ".pdf"); jm.setInputStreamContentType("application/pdf"); break; case SVG: jm.setInputStreamName(deliveryOptions.getInstanceId() + ".pdf"); jm.setInputStreamContentType("application/pdf"); break; default: jm.setInputStreamName(deliveryOptions.getInstanceId() + ".htm"); jm.setInputStreamContentType("text/html"); } jm.mailSend(); } catch (JavaMailerException e) { log.error("Caught JavaMailer exception sending report", e); } }
/** * Sends message based on properties and fields configured for the service. * * @param mailParms * @return a PollStatus */ private PollStatus sendTestMessage(final MailTransportParameters mailParms) { PollStatus status = PollStatus.unavailable("Test not completed."); final long interval = mailParms.getSendTestAttemptInterval(); final TimeoutTracker tracker = new TimeoutTracker( mailParms.getParameterMap(), mailParms.getRetries(), mailParms.getTimeout()); for (tracker.reset(); tracker.shouldRetry(); tracker.nextAttempt()) { tracker.startAttempt(); LOG.debug( "sendTestMessage: sending mail attempt: {}, elapsed time: {}ms", (tracker.getAttempt() + 1), String.format("%.2f", tracker.elapsedTimeInMillis())); try { final JavaMailer sendMailer = createMailer(mailParms); overRideDefaultProperties(mailParms, sendMailer); sendMailer.mailSend(); status = PollStatus.available(); break; } catch (final JavaMailerException e) { status = PollStatus.unavailable(e.getLocalizedMessage()); } if (tracker.shouldRetry()) { delayTest(status, interval); } } return status; }