Package org.pentaho.actionsequence.dom.actions

Examples of org.pentaho.actionsequence.dom.actions.EmailAction


    if ( !( getActionDefinition() instanceof EmailAction ) ) {
      error( Messages.getInstance().getErrorString(
          "ComponentBase.ERROR_0001_UNKNOWN_ACTION_TYPE", getActionDefinition().getElement().asXML() ) ); //$NON-NLS-1$
      result = false;
    } else {
      EmailAction emailAction = (EmailAction) getActionDefinition();

      IActionInput to = emailAction.getTo();
      IActionInput subject = emailAction.getSubject();
      IActionInput plainMsg = emailAction.getMessagePlain();
      IActionInput htmlMsg = emailAction.getMessageHtml();

      if ( to == ActionInputConstant.NULL_INPUT ) {
        error( Messages.getInstance().getErrorString( "Email.ERROR_0001_TO_NOT_DEFINED", getActionName() ) ); //$NON-NLS-1$
        result = false;
      } else if ( subject == ActionInputConstant.NULL_INPUT ) {
View Full Code Here


  }

  @Override
  public boolean executeAction() {
    EmailAction emailAction = (EmailAction) getActionDefinition();

    String messagePlain = emailAction.getMessagePlain().getStringValue();
    String messageHtml = emailAction.getMessageHtml().getStringValue();
    String subject = emailAction.getSubject().getStringValue();
    String to = emailAction.getTo().getStringValue();
    String cc = emailAction.getCc().getStringValue();
    String bcc = emailAction.getBcc().getStringValue();
    String from = emailAction.getFrom().getStringValue( defaultFrom );
    if ( from.trim().length() == 0 ) {
      from = defaultFrom;
    }

    /*
     * if( context.getInputNames().contains( "attach" ) ) { //$NON-NLS-1$ Object attachParameter =
     * context.getInputParameter( "attach" ).getValue(); //$NON-NLS-1$ // We have a list of attachments, each element of
     * the list is the name of the parameter containing the attachment // Use the parameter filename portion as the
     * attachment name. if ( attachParameter instanceof String ) { String attachName = context.getInputParameter(
     * "attach-name" ).getStringValue(); //$NON-NLS-1$ AttachStruct attachData = getAttachData( context,
     * (String)attachParameter, attachName ); if ( attachData != null ) { attachments.add( attachData ); } } else if (
     * attachParameter instanceof List ) { for ( int i = 0; i < ((List)attachParameter).size(); ++i ) { AttachStruct
     * attachData = getAttachData( context, ((List)attachParameter).get( i ).toString(), null ); if ( attachData != null
     * ) { attachments.add( attachData ); } } } else if ( attachParameter instanceof Map ) { for ( Iterator it =
     * ((Map)attachParameter).entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry)it.next();
     * AttachStruct attachData = getAttachData( context, (String)entry.getValue(), (String)entry.getKey() ); if (
     * attachData != null ) { attachments.add( attachData ); } } } }
     *
     * int maxSize = Integer.MAX_VALUE; try { maxSize = new Integer( props.getProperty( "mail.max.attach.size" )
     * ).intValue(); } catch( Throwable t ) { //ignore if not set to a valid value }
     *
     * if ( totalAttachLength > maxSize ) { // Sort them in order TreeMap tm = new TreeMap(); for( int idx=0;
     * idx<attachments.size(); idx++ ) { // tm.put( new Integer( )) } }
     */

    if ( ComponentBase.debug ) {
      debug( Messages.getInstance().getString( "Email.DEBUG_TO_FROM", to, from ) ); //$NON-NLS-1$
      debug( Messages.getInstance().getString( "Email.DEBUG_CC_BCC", cc, bcc ) ); //$NON-NLS-1$
      debug( Messages.getInstance().getString( "Email.DEBUG_SUBJECT", subject ) ); //$NON-NLS-1$
      debug( Messages.getInstance().getString( "Email.DEBUG_PLAIN_MESSAGE", messagePlain ) ); //$NON-NLS-1$
      debug( Messages.getInstance().getString( "Email.DEBUG_HTML_MESSAGE", messageHtml ) ); //$NON-NLS-1$
    }

    if ( ( to == null ) || ( to.trim().length() == 0 ) ) {

      // Get the output stream that the feedback is going into
      OutputStream feedbackStream = getFeedbackOutputStream();
      if ( feedbackStream != null ) {
        createFeedbackParameter(
            "to", Messages.getInstance().getString( "Email.USER_ENTER_EMAIL_ADDRESS" ), "", "", true ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        setFeedbackMimeType( "text/html" ); //$NON-NLS-1$
        return true;
      } else {
        return false;
      }
    }
    if ( subject == null ) {
      error( Messages.getInstance().getErrorString( "Email.ERROR_0005_NULL_SUBJECT", getActionName() ) ); //$NON-NLS-1$
      return false;
    }
    if ( ( messagePlain == null ) && ( messageHtml == null ) ) {
      error( Messages.getInstance().getErrorString( "Email.ERROR_0006_NULL_BODY", getActionName() ) ); //$NON-NLS-1$
      return false;
    }

    if ( getRuntimeContext().isPromptPending() ) {
      return true;
    }

    try {
      Properties props = new Properties();
      final IEmailService service =
          PentahoSystem.get( IEmailService.class, "IEmailService", PentahoSessionHolder.getSession() );
      props.put( "mail.smtp.host", service.getEmailConfig().getSmtpHost() );
      props.put( "mail.smtp.port", ObjectUtils.toString( service.getEmailConfig().getSmtpPort() ) );
      props.put( "mail.transport.protocol", service.getEmailConfig().getSmtpProtocol() );
      props.put( "mail.smtp.starttls.enable", ObjectUtils.toString( service.getEmailConfig().isUseStartTls() ) );
      props.put( "mail.smtp.auth", ObjectUtils.toString( service.getEmailConfig().isAuthenticate() ) );
      props.put( "mail.smtp.ssl", ObjectUtils.toString( service.getEmailConfig().isUseSsl() ) );
      props.put( "mail.smtp.quitwait", ObjectUtils.toString( service.getEmailConfig().isSmtpQuitWait() ) );
      props.put( "mail.from.default", service.getEmailConfig().getDefaultFrom() );
      String fromName = service.getEmailConfig().getFromName();
      if ( StringUtils.isEmpty( fromName ) ) {
        fromName = Messages.getInstance().getString( "schedulerEmailFromName" );
      }
      props.put( "mail.from.name", fromName );
      props.put( "mail.debug", ObjectUtils.toString( service.getEmailConfig().isDebug() ) );

      Session session;
      if ( service.getEmailConfig().isAuthenticate() ) {
        props.put( "mail.userid", service.getEmailConfig().getUserId() );
        props.put( "mail.password", service.getEmailConfig().getPassword() );
        Authenticator authenticator = new EmailAuthenticator();
        session = Session.getInstance( props, authenticator );
      } else {
        session = Session.getInstance( props );
      }

      // debugging is on if either component (xaction) or email config debug is on
      if ( service.getEmailConfig().isDebug() || ComponentBase.debug ) {
        session.setDebug( true );
      }

      // construct the message
      MimeMessage msg = new MimeMessage( session );
      if ( from != null ) {
        msg.setFrom( new InternetAddress( from ) );
      } else {
        // There should be no way to get here
        error( Messages.getInstance().getString( "Email.ERROR_0012_FROM_NOT_DEFINED" ) ); //$NON-NLS-1$
      }

      if ( ( to != null ) && ( to.trim().length() > 0 ) ) {
        msg.setRecipients( Message.RecipientType.TO, InternetAddress.parse( to, false ) );
      }
      if ( ( cc != null ) && ( cc.trim().length() > 0 ) ) {
        msg.setRecipients( Message.RecipientType.CC, InternetAddress.parse( cc, false ) );
      }
      if ( ( bcc != null ) && ( bcc.trim().length() > 0 ) ) {
        msg.setRecipients( Message.RecipientType.BCC, InternetAddress.parse( bcc, false ) );
      }

      if ( subject != null ) {
        msg.setSubject( subject, LocaleHelper.getSystemEncoding() );
      }

      EmailAttachment[] emailAttachments = emailAction.getAttachments();
      if ( ( messagePlain != null ) && ( messageHtml == null ) && ( emailAttachments.length == 0 ) ) {
        msg.setText( messagePlain, LocaleHelper.getSystemEncoding() );
      } else if ( emailAttachments.length == 0 ) {
        if ( messagePlain != null ) {
          msg.setContent( messagePlain, "text/plain; charset=" + LocaleHelper.getSystemEncoding() ); //$NON-NLS-1$         
View Full Code Here

TOP

Related Classes of org.pentaho.actionsequence.dom.actions.EmailAction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.