4 Replies Latest reply on Dec 22, 2006 8:25 AM by jainer

    Sending Emails?

    zephren

      How can I have an email sent to a user once a state has been completed? I want to be able to notify the next person that it is their turn to do the next task.

        • 1. Re: Sending Emails?
          highlnd

          What I would do is create an action that is executed on the node-enter event on each task node. This action would send an email to the person responsible for finishing the task.

          • 2. Re: Sending Emails?
            saviola

            See jBPM 3.2 in the CVS. It has build-in functionality for sending emails.

            • 3. Re: Sending Emails?
              kukeltje

              it can be done with 3.1 to. Just create a simple basic actionhandler that sends an email on the node-leave event of a tasknode.

              • 4. Re: Sending Emails?
                jainer

                Hi:

                This is a code to send mails.. obviously you must to have your own mail jar

                package controlcorrespondencia.handlers.actions;
                
                import java.util.Iterator;
                
                import javax.naming.*;
                import javax.rmi.PortableRemoteObject;
                
                import org.apache.commons.logging.Log;
                import org.apache.commons.logging.LogFactory;
                
                import org.jbpm.graph.def.ActionHandler;
                import org.jbpm.graph.exe.ExecutionContext;
                import org.jbpm.taskmgmt.exe.TaskInstance;
                
                import com.sumset.beesoft.correo.ServicioCorreoHome;
                import com.sumset.beesoft.correo.ServicioCorreo;
                import com.sumset.beesoft.correo.CorreoVO;
                
                public class Correo implements ActionHandler{
                
                 ServicioCorreoHome miServicioCorreoHome;
                 ServicioCorreo miServicioCorreo;
                
                 public void execute(ExecutionContext executionContext){
                 String processDefinitionName = executionContext.getProcessDefinition().getName();
                
                 Iterator iterTask = executionContext.getTaskMgmtInstance().getTaskInstances().iterator();
                
                 while (iterTask.hasNext()) {
                 TaskInstance nextTask = (TaskInstance) iterTask.next();
                
                 if(nextTask.isSignalling()){
                
                 long idTarea = nextTask.getId();
                 String nombreTarea = nextTask.getName();
                 String usuario = nextTask.getActorId();
                 String asunto = nextTask.getName();
                
                 try{
                
                 Context context = new InitialContext();
                 Object servicioCorreo = context.lookup("ServicioCorreo");
                 miServicioCorreoHome = (ServicioCorreoHome) PortableRemoteObject.narrow(servicioCorreo, ServicioCorreoHome.class);
                 miServicioCorreo = miServicioCorreoHome.create();
                
                 String origen = "f-aristi@sumset.com";
                 String destino = "jquiceno@sumset.com";
                 String Url = "http://localhost:8080/jbpm/faces/otroLogin.jsp?idTarea=" + idTarea +
                 "&usuario=" + usuario + "&nombreProceso=" + processDefinitionName;
                
                 String mensaje = "<a href=\"" + Url + "\" target=\"_blank\" "+
                 "title=\"Este enlace externo se abrirá en una nueva ventana\">" +
                 nombreTarea + "</a>";
                
                 CorreoVO correo = new CorreoVO(origen,destino,asunto,new java.util.Date(),"1",mensaje,"sistema");
                 miServicioCorreo.enviarCorreo(correo);
                
                 log.debug("correo enviado");
                
                 }catch (Exception e){
                 System.out.println("Se produjo un error en la inicialización del servicio de correo:");
                 e.printStackTrace();
                 }
                 }
                 }
                
                 }
                
                 private static final Log log = LogFactory.getLog(Correo.class);
                
                }
                



                <task-node name="Envio Correspondencia">
                 <task name="Despachar Correspondencia" swimlane="secretaria auxiliar">
                 <controller>
                 <variable name="ipTTN6Comentario" access="read,write,required" mapped-name="Comentario"/>
                 </controller>
                 </task>
                 <event type="after-signal">
                 <action name="Enviar Correo" class="controlcorrespondencia.handlers.actions.Correo"></action>
                 </event>
                 <transition name="" to="Verificacion"></transition>
                 </task-node>
                


                Regards

                jainer e.