예제 #1
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());
  }
예제 #2
0
  private JavaMailer createMailer(final MailTransportParameters mailParms)
      throws JavaMailerException {
    final JavaMailer sendMailer = new JavaMailer(mailParms.getJavamailProperties());
    final String mailPropsPrefix =
        new StringBuilder("mail.").append(mailParms.getSendTestTransport()).append('.').toString();
    final Properties props = sendMailer.getSession().getProperties();

    // user
    props.setProperty(mailPropsPrefix + "user", mailParms.getSendTestUserName());
    sendMailer.setUser(mailParms.getSendTestUserName());
    sendMailer.setPassword(mailParms.getSendTestPassword());

    // host
    props.setProperty(mailPropsPrefix + "host", mailParms.getSendTestHost());
    sendMailer.setMailHost(mailParms.getSendTestHost());

    // port
    props.setProperty(mailPropsPrefix + "port", String.valueOf(mailParms.getSendTestPort()));
    sendMailer.setSmtpPort(mailParms.getSendTestPort());

    // connectiontimeout
    // Override this with configured javamail property because this setting is a generic timeout
    // value
    if (!props.containsKey(mailPropsPrefix + "connectiontimeout")) {
      props.setProperty(
          mailPropsPrefix + "connectiontimeout", String.valueOf(mailParms.getTimeout()));
    }

    // timeout
    // Override this with configured javamail property because this setting is a generic timeout
    // value
    if (!props.containsKey(mailPropsPrefix + "timeout")) {
      props.setProperty(mailPropsPrefix + "timeout", String.valueOf(mailParms.getTimeout()));
    }

    // from
    props.setProperty(mailPropsPrefix + "from", mailParms.getSendTestFrom());
    sendMailer.setFrom(mailParms.getSendTestFrom());

    // auth
    props.setProperty(mailPropsPrefix + "auth", String.valueOf(mailParms.isSendTestUseAuth()));
    sendMailer.setAuthenticate(mailParms.isSendTestUseAuth());

    // quitwait
    props.setProperty(
        mailPropsPrefix + "quitwait", String.valueOf(mailParms.isSendTestIsQuitWait()));
    sendMailer.setQuitWait(mailParms.isSendTestIsQuitWait());

    // socketFactory.class
    // socketFactory.port
    if (mailParms.isSendTestIsSslEnable()) {

      // override this hard coded default if this property is specified
      if (!props.containsKey(mailPropsPrefix + "socketFactory.class")) {
        props.setProperty(
            mailPropsPrefix + "socketFactory.class", "javax.net.ssl.SSLSocketFactory");
      }
      props.setProperty(
          mailPropsPrefix + "socketFactory.port", String.valueOf(mailParms.getSendTestPort()));
      sendMailer.setSmtpPort(mailParms.getSendTestPort());
    }
    sendMailer.setSmtpSsl(mailParms.isSendTestIsSslEnable());

    // starttls.enable
    props.setProperty(
        mailPropsPrefix + "starttls.enable", String.valueOf(mailParms.isSendTestStartTls()));
    sendMailer.setStartTlsEnabled(mailParms.isSendTestStartTls());
    sendMailer.addExtraHeader(MTM_HEADER_KEY, m_headerValue);

    sendMailer.setSession(Session.getInstance(props, sendMailer.createAuthenticator()));

    return sendMailer;
  }