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

frederikherema1
Star Contributor
Star Contributor
There is no file-upload built in yet into Explorer1 webapp, so I'm affraid nothing out of the box will do. Don't really have an good suggestion on how you should get started on that…

If you consider using Explorer2 (will be released in distro next release), you can always use the formProperties and create a custom formProperty type with file-upload field using vaadin…

kavi
Champ in-the-making
Champ in-the-making
Hi ,
if not how to send attachments for emails?
Is there any other way?

Thanks,
Kavi

frederikherema1
Star Contributor
Star Contributor
You could use the Commons Email directly, through a service-task and add the attachments through that. Take a look at the MailActivityBehaviour…

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

Being new to activiti can u tel me as what u mean by Commons Email?

How to add Commons Email directly? Any sample or eg?

Thanks,
kavi

frederikherema1
Star Contributor
Star Contributor
Activiti allows you to write any java-code you want and use it as a piece of your process -> JavaDelegate. See http://activiti.org/userguide/index.html#bpmnJavaServiceTask

Since we use commons-email (apache) to send emails in activiti, you can use it, the same way as the MailActivityBehavilour does… Look at the code in org.activiti.engine.impl.bpmn.behavior.MailActivityBehavior.

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

Thanks a lot for ur reply.
Now i used Java service class as <serviceTask completionQuantity="1"  activiti:class="org.activiti.engine.impl.bpmn.behavior.MailActivityBehavior" id="sid-1430FC68-FA04-41E0-9EDB-A9A0329F42A3" implementation="webService" isForCompensation="false" name="Email to applicant on status &quot;OnHold&quot;" startQuantity="1">…….
      

Now for this class where can i write the code?
For commons email the code is EmailAttachment attachment = new EmailAttachment();
  attachment.setPath("mypictures/john.jpg");
  attachment.setDisposition(EmailAttachment.ATTACHMENT);
  attachment.setDescription("Picture of John");
  attachment.setName("John");
Should i write this code?
If so where? if not is it enough to set field injection in extension element as <activiti:field name="to" expression="${Email}" />. Likewise what field is used for attachment?

Thanks,
kavi

frederikherema1
Star Contributor
Star Contributor
As I said in the first reply, MailActivityBehaviour doesn't have a field for attachment, you will have to write your OWN JavaDelegate that will send the email with an attachment. How you get the attachment there is all up to you…

Take a look at the userguide in the chapters about field injection in JavaDelegates on how to use that to configure your Javadelegate from a bpmn-process.

kavi
Champ in-the-making
Champ in-the-making
Hi ,
sorry for my misunderstanding.

In that user guide they have given "declare a 'extensionElements' XML element before the actual field injection declarations". What is mean by that?

If i am using "org.activiti.engine.impl.bpmn.behavior.MailActivityBehavior" class what should i declare? What fields should i use for attachment?

Kindly clarify as i am not able ti proceed further.

Thanks,
kavi

frederikherema1
Star Contributor
Star Contributor
BPMN scheme requires this, wrapping all custom XML-elements in a extentionsElements element, so all NON-BPMN stuff (eg. activiti:field) is placed here:

<serviceTask id="javaService"
    name="Java service invocation"
    activiti:class="org.activiti.examples.bpmn.servicetask.ToUpperCaseFieldInjected">
    <extensionElements>
      <activiti:field name="text" stringValue="Hello World" />
  </extensionElements>          
</serviceTask>      

The MailActivityBehaviour is actually the class that is used when using the mail-task. So when declaring a serviceTask with activiti:type=mail, this is used. So it only has the fields that are shown below, NO field for attachment:

<serviceTask id="sendMail" activiti:type="mail">
  <extensionElements>
    <activiti:field name="from" stringValue="order-shipping@thecompany.com" />
    <activiti:field name="to" expression="${recipient}" />
    <activiti:field name="subject" expression="Your order ${orderId} has been shipped" />
    <activiti:field name="html">
      <activiti:expression>
        <![CDATA[
          <html>
            <body>
              Hello ${male ? 'Mr.' : 'Mrs.' } ${recipientName},<br/><br/>
                
              As of ${now}, your order has been <b>processed and shipped</b>.<br/><br/>
                 
              Kind regards,<br/>
                 
              TheCompany.
            </body>
          </html>
        ]]>
      </activiti:expression>
    </activiti:field>     
  </extensionElements>
</serviceTask>