cancel
Showing results for 
Search instead for 
Did you mean: 

SendMail in Activiti not working...

mcasanket
Champ on-the-rise
Champ on-the-rise
Hi All,  Smiley Very Happy
   I am using Activiti. I have put one service task that sends a mail. But I am getting errors when I start the server.

The task in 20bpm.xml.

<!– Send email Task starts –>
<serviceTask id="sendMail" activiti:type="mail">
  <extensionElements>
    <activiti:field name="from" stringValue="order-shipping@thecompany.com" />
    <activiti:field name="to" expression="mcasanket70@gmail.com" />
    <activiti:field name="subject" expression="Your order has been shipped" />
    <activiti:field name="html">
      <activiti:expression>
        <![CDATA[
          <html><body> This is an auto generated email. </body></html>
        ]]>
      </activiti:expression>
    </activiti:field>     
  </extensionElements>
</serviceTask>               
<!– Send email Task ends –>

The exception is :
org.activiti.engine.ActivitiException: couldn't instantiate class org.activiti.engine.impl.bpmn.behavior.MailActivityBehavior

I have read about activiti.cfg.xml  file to configure the mail server. But I don't know where to find this file.

Thanking you!
4 REPLIES 4

afaust
Legendary Innovator
Legendary Innovator
Hello,

if you are using Activiti bunled within Alfresco, you should not be using the Mail task from Activiti. Instead use an Alfresco component for JavaScript execution and generate/send an email using the Alfresco email action. An example of this is illustrated on the Workflow with Activiti wiki page.

Regards
Axel

angello0571
Champ on-the-rise
Champ on-the-rise
Hi everyone!

I am here to request your help one more time. I checked in the forum and someone put a wiki link with this page http://wiki.alfresco.com/wiki/Workflow_with_Activiti.
That is a great example where explain how to send an email in a userTask event because the activiti's emailTask does not work.
I did the example and it works perfectly into the listener of userTask.

Well, my requirement is the next one:

I'm doing a workflow, it has a boundary timer in a user task that after 1 minute should send
an email if the task has not been completed yet. I figure out to use a scriptTask to trigger the email into the start event.
Let me show you:
<!– Using a Script task –>
<scriptTask id="scripttask1" name="Send Email" scriptFormat="javascript">
        <extensionElements>
         <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
           <activiti:field name="script">
            <activiti:string>
                var mail = actions.create("mail");
                mail.parameters.to = "a@gmail.com";
                mail.parameters.subject = "send a workflow's email. second test! " + bpm_workflowDescription;
                mail.parameters.from = "b@gmail.com";
                mail.parameters.text = "2nd Test message! ";
                mail.execute(bpm_package);
            </activiti:string>
           </activiti:field>
         </activiti:executionListener>
        </extensionElements>
        <script><![CDATA[]]></script>
      </scriptTask>
When the boundary timer runs, I got an exception:
Exception in thread "pool-1-thread-4" org.activiti.engine.ActivitiException: org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener doesn't implement interface org.activiti.engine.delegate.ExecutionListener nor interface org.activiti.engine.delegate.JavaDelegate
   at org.activiti.engine.impl.bpmn.helper.ClassDelegate.getExecutionListenerInstance(ClassDelegate.java:80)
   at org.activiti.engine.impl.bpmn.helper.ClassDelegate.notify(ClassDelegate.java:66)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:38)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:76)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:481)  
I did a second try using this:   
<!– Using the alfresco's Script task –>
<scriptTask id="scripttask1" name="Send Email" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate">
  <extensionElements>
     <activiti:field name="script">
      <activiti:string>
             var mail = actions.create("mail");
             mail.parameters.to = "a@gmail.com";
             mail.parameters.subject = "send a workflow's email. second test! " + bpm_workflowDescription;
             mail.parameters.from = "b@gmail.com";
             mail.parameters.text = "2nd Test message! ";
             mail.execute(bpm_package);
      </activiti:string>
     </activiti:field>
  </extensionElements>
</scriptTask>
Again I get an exception:
Exception in thread "pool-1-thread-1" java.lang.NullPointerException
   at javax.script.ScriptEngineManager.getEngineByName(ScriptEngineManager.java:199)
   at org.activiti.engine.impl.scripting.ScriptingEngines.evaluate(ScriptingEngines.java:63)
   at org.activiti.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior.execute(ScriptTaskActivityBehavior.java:43)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:40)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:76)
Does anybody could help me with a "tip" or a way to solve this ?
Maybe I'm not using the correct Class, or I have to use another component, anyway. I'll be alert of any help.
Thanks in advance guys.

afaust
Legendary Innovator
Legendary Innovator
Hello,

the event type in your first example appears to be incorrect. "start" and "end" are only possble for execution listeners - for task listeners you should use "create", "assign" or "complete".
By the way: Why are you using a ScriptTaskListener in an empty scriptTask? Better put that ScriptTaskListener on the following userTask (if there is only one) and save yourself the scriptTask.

Regards
Axel

angello0571
Champ on-the-rise
Champ on-the-rise
Hi Axel,

That is exactly I was looking for more information about the Activiti API.

Ijust had to change the class Listener using org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener instead of org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener

The script right now looks like this:

<scriptTask id="scripttask1" name="Send Email" scriptFormat="javascript">
        <extensionElements>
         <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
           <activiti:field name="script">
            <activiti:string>
                var mail = actions.create("mail");
                mail.parameters.to = "a@gmail.com";
                mail.parameters.subject = "send a workflow's email. second test! " + bpm_workflowDescription;
                mail.parameters.from = "b@gmail.com";
                mail.parameters.text = "2nd Test message! ";
                mail.execute(bpm_package);
            </activiti:string>
           </activiti:field>
         </activiti:executionListener>
        </extensionElements>
        <script><![CDATA[]]></script>
      </scriptTask>

Ah! I didn´t use a userTask because the email should be sent automaticly, that is the reason why I decided to use a scriptTask.

1 minute was just an example, I have to trigger the email after 5 days Smiley Very Happy

Now that's is working!

Thank you for your time.