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);
   }
 }
Esempio n. 2
0
  /**
   * Override some fields in the JavaMailer class. TODO: This needs re-factoring!
   *
   * @param mailParms
   * @param sendMailer
   */
  private void overRideDefaultProperties(
      final MailTransportParameters mailParms, final JavaMailer sendMailer) {
    sendMailer.setFrom(mailParms.getSendTestFrom());

    sendMailer.getSession().setDebug(mailParms.isSendTestDebug());
    sendMailer.setDebug(mailParms.isSendTestDebug());

    sendMailer.setEncoding(mailParms.getSendTestMessageEncoding());
    sendMailer.setMailer(mailParms.getSendTestMailer());
    sendMailer.setMailHost(mailParms.getSendTestHost());

    // char_set, encoding, m_contentType
    sendMailer.setMessageText(mailParms.getSendTestMessageBody());
    sendMailer.setCharSet(mailParms.getSendTestCharSet());
    sendMailer.setContentType(mailParms.getSendTestMessageContentType());

    sendMailer.setSmtpSsl(mailParms.isSendTestIsSslEnable());

    sendMailer.setSubject(mailParms.getComputedTestSubject());
    sendMailer.setTo(mailParms.getSendTestRecipeint());
    sendMailer.setTransport(mailParms.getSendTestTransport());
    sendMailer.setUseJMTA(mailParms.isSendTestUseJmta());
  }