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

moushmi
Champ in-the-making
Champ in-the-making
Make sure the field that is returned, implements Field, see SelectUserField:


/**
* Field which allows you to select a user. The field-value is the
* id of the selected user.
*
* @author Frederik Heremans
*/
public class SelectUserField extends HorizontalLayout implements Field {

Hi frederikheremans,

I made these changes in MyUploader.java class:
package org.activiti.explorer.ui.form;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Collection;

import com.vaadin.data.Property;
import com.vaadin.data.Validator;
import com.vaadin.data.Validator.InvalidValueException;
import com.vaadin.terminal.FileResource;
import com.vaadin.ui.*;

public  class MyUploader extends CustomComponent
                        implements Upload.SucceededListener,
                                   Upload.FailedListener,
                                   Upload.Receiver,Field{
But i get compile time error on MyUploader as :The inherited method AbstractComponent.focus() cannot hide the public abstract method in Component.Focusable.

How do i resolve this..

Thanks and best regards,
Moushmi

moushmi
Champ in-the-making
Champ in-the-making
Make sure the field that is returned, implements Field, see SelectUserField:


/**
* Field which allows you to select a user. The field-value is the
* id of the selected user.
*
* @author Frederik Heremans
*/
public class SelectUserField extends HorizontalLayout implements Field {


HI,

Is there any way to do file upload attachments using form renderers?
Can you please confirm any API using vaadin which can help me in file upload?
As of now i could find no API supporting the file upload using renderers similar to SelectUserField/textarea/string/boolean..types.The Upload.class file throws me an error as earlier mentioned in my last post as:Compile time error on MyUploader as :The inherited method AbstractComponent.focus() cannot hide the public abstract method in Component.Focusable.

Please provide some breakthrough.I will be realy greatful to you all.

Thanks and best regards,
Moushmi

dqvn
Champ in-the-making
Champ in-the-making
In activiti-engine/src/main/java/org/activiti/engine/impl/bpmn/behavior/MailActivityBehavior.java
Add more code at line 87 up to line 90 the code below: (tested and running in my project)

TaskService taskService = execution.getEngineServices().getTaskService();
String processId = execution.getProcessInstanceId();

List<Attachment> attachments = taskService.getProcessInstanceAttachments(processId);
for (Attachment attachment : attachments)
{

  String fileOutputPath = "/tmp/" + attachment.getName();
  InputStream fileInput = taskService.getAttachmentContent(attachment.getId());
  OutputStream fileOutput;
  try {
      fileOutput = new FileOutputStream(fileOutputPath);
      IOUtils.copy(fileInput, fileOutput);
      fileInput.close();
      fileOutput.flush();
      fileOutput.close();
  } catch (FileNotFoundException e) {
      log.severe("WRITING FILE FOR EMAIL ATTACHMENT - FileNotFoundException: " + e.getStackTrace());
  } catch (IOException e) {
      log.severe("WRITING FILE FOR EMAIL ATTACHMENT - IOException: " + e.getStackTrace());
  }

  // Create the attachment
  EmailAttachment emailAttachment = new EmailAttachment();
  emailAttachment.setPath(fileOutputPath);
  emailAttachment.setDisposition(EmailAttachment.ATTACHMENT);

  // Create the email message
  MultiPartEmail mpemail = (MultiPartEmail) email;
  // add the attachment
  mpemail.attach(emailAttachment);
  // send the email
  mpemail.send();
}

luca_stancapian
Champ in-the-making
Champ in-the-making
You can simply add an expression in the mail task of the bpmn description as it:

<code>
<serviceTask id="mailtask1" name="Receive Ticket" activiti:type="mail">
     …….

        <activiti:field name="attachments">
          <activiti:expression><![CDATA[#{file_path}]]></activiti:expression>
        </activiti:field>
  …….
</code>
Unfortunately the feature is not present in the eclipse activiti plugin so it must be done inside the xml file. Then valorize the variable inside a TaskListener. Here a sample:

<code>
@Override
public void notify(DelegateTask delegateTask) {
             …..
    delegateTask.getExecution().createVariableLocal("file_path", "/my_directory/my_sample_file.pdf");
             …..
</code>

If the file exists automatically is sent through email