cancel
Showing results for 
Search instead for 
Did you mean: 

Send attachments with mail

kavi
Champ in-the-making
Champ in-the-making
Hi ,

Is it possible to send attachments to mail using <input type="file"> value?
I have uploaded a file in a form using 
<input type="file" name="datafile" size="40">

Now i want to send that file in mail using service task.
How to do it?
Any idea.

Thanks,
Kv
33 REPLIES 33

kavi
Champ in-the-making
Champ in-the-making
Hi ,

Now i can get you.
So how can i write a class for mail with attachment ?

Is the class " org.activiti.engine.impl.bpmn.behavior.MailActivityBehavior" enough or which class i should use for using Commons email technique.

For attachment using commons email i found the code from the link http://commons.apache.org/email/userguide.html.

Where can i write the code and how can i assign values for the fields in the class?

Kindly help me out.

Thanks,
kavi

jbarrez
Star Contributor
Star Contributor
No, the mail task doesnt allow to add attachment.
But it is very easy to write your own (or extends the existing) ActivityBehaviour to do that.

kavi
Champ in-the-making
Champ in-the-making
Hi ,

I dont no how to write my own being new to activiti.

I have my own code. But where to include my code in java service task?

Thanks,
kavi

frederikherema1
Star Contributor
Star Contributor
Implement a java-class that implements JavaDelegate, and use that class in your process:

serviceTask id="javaService"
             name="My Java Service Task"
             activiti:class="org.activiti.MyJavaDelegate" />

public class ToUppercase implements JavaDelegate {
 
  public void execute(DelegateExecution execution) throws Exception {
    String var = (String) execution.getVariable("input");
    var = var.toUpperCase();
    execution.setVariable("input", var);
  }
 
}

You can read all this is the userguide, examples are included as unit-tests… That should do to get you started

kavi
Champ in-the-making
Champ in-the-making
Hi ,

I have created a class for mail attachment and wrote the code in myname.java.
In service task i included
<serviceTask completionQuantity="1"  activiti:class="mailattachment" id="sid-1430FC68-FA04-41E0-9EDB-A9A0329F42A3" implementation="webService" isForCompensation="false" name="Email to applicant on status &quot;OnHold&quot;" startQuantity="1">….
But when i run my process when it comes to this service it says "05280002 Wrapped Exception (with status template): couldn't instantiate class mailattachment ".

When i searched in forum i found that i should include the file in as jar in "activiti\apps\apache-tomcat-6.0.32\webapps\activiti-rest\WEB-INF\lib" .
How to create jar file for .java file.?

kavi
Champ in-the-making
Champ in-the-making
Hi,

When i tried to build my java file it says
package org.apache.commons.mail does not exist
import org.apache.commons.mail.EmailException;

What am i missing?

Thanks,
kavi

kavi
Champ in-the-making
Champ in-the-making
Hi ,

I am not able to compile any of the java file present in
C:\activiti\workspace\activiti-engine-examples\src\main\java\org\activiti\examples\bpmn\servicetask
.

     It says import error. It seems the lib reference is missing.

How to include reference. Eg:import org.activiti.engine.delegate.Expression; says cannot find org.activiti.engine.delegate.

So how to compile this?

Thanks
kavi

jbarrez
Star Contributor
Star Contributor
Just add the Activiti jar to your classpath.

moushmi
Champ in-the-making
Champ in-the-making
HI @frederikheremans,

-As suggested by you,I tried implementing the Business logic in my java service task via commons email.
-Created 1 attachment field in the bpmn20.xml file as:-  <activiti:formProperty id="attachment to be provided" expression="${attachment}" name="attachment" type="string" required="false"/>
-Next I tried to modify the source code via MailActivityBehavior class.

This is throwing me an error as(partially quoted) :
Caused by: org.activiti.engine.ActivitiException: couldn't find type for org.apache.commons.mail.EmailAttachment@60e2ecb3
at org.activiti.engine.impl.variable.DefaultVariableTypes.findVariableType(DefaultVariableTypes.java:62)[113Smiley Surprisedrg.activiti.engine:5.9.0]
at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.createVariableLocal(VariableScopeImpl.java:223)[113Smiley Surprisedrg.activiti.engine:5.9.0]
at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.setVariable(VariableScopeImpl.java:175)[113Smiley Surprisedrg.activiti.engine:5.9.0]
at com.causeway.Example.MailInit.execute(MailInit.java:47)[149:activiti-examples:1.0.0.SNAPSHOT]
at org.activiti.engine.impl.delegate.JavaDelegateInvocation.invoke(JavaDelegateInvocation.java:34)[113Smiley Surprisedrg.activiti.engine:5.9.0]
at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)[113Smiley Surprisedrg.activiti.engine:5.9.0]
at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)[113Smiley Surprisedrg.activiti.engine:5.9.0]
at org.activiti.engine.impl.bpmn.behavior.ServiceTaskJavaDelegateActivityBehavior.execute(ServiceTaskJavaDelegateActivityBehavior.java:49)[113Smiley Surprisedrg.activiti.engine:5.9.0]
at org.activiti.engine.impl.bpmn.behavior.ServiceTaskJavaDelegateActivityBehavior.execute(ServiceTaskJavaDelegateActivityBehavior.java:40)[113Smiley Surprisedrg.activiti.engine:5.9.0]
at org.activiti.engine.impl.bpmn.helper.ClassDelegate.execute(ClassDelegate.java:115)[113Smiley Surprisedrg.activiti.engine:5.9.0]


Please let me know the type for email attachment to be according to the error?
Grateful if you could provide your email id.

Thanks in advance!!

trademak
Star Contributor
Star Contributor
Hi,

It looks like you try to set a variable of type EmailAttachment in the process instance context, is that right?
You can't do that because EmailAttachment doesn't implement the Serializable interface. Therefore this error message.

Best regards,

Tijs