How send email document attachment using workflow service task

Showing results for 
Search instead for 
Did you mean: 
Established Member

How send email document attachment using workflow service task


I am new on Alfresco community version 5.2 

I need send email when new document is uploaded in folder and attach it to the email.

I found some approaches but I cannot use any of them.

I created rule and script like this 

Next I have tried start workflow by script and send email using service task (JavaDelegateClass) but there is problem get document

1) I have to set document as parameter in script

         workflow.parameters.docnode = document;

2) in java service task (JavaDelegateClass) 

         ActivitiScriptNode scriptNode = (ActivitiScriptNode) execution.getVariable("docnode");

         NodeRef docref = scriptNode.getNodeRef();

         ContentReader reader = contentService.getReader(docref, ContentModel.PROP_CONTENT);
         InputStream originalInputStream = reader.getContentInputStream();

         messageBodyPart = new MimeBodyPart(originalInputStream);

but contentService.getReader(docref, ContentModel.PROP_CONTENT) causes an exception

Caused by: java.lang.NullPointerException

docref = workspace://SpacesStore/c20bd21d-90d3-497f-9e0a-28951649116e

I search docref in node browser and

00300000 Node workspace://SpacesStore/c20bd21d-90d3-497f-9e0a-28951649116e does not exist.

What is the problem?

Help me please how can JavaDelegateClass access to document in workflow.

Thanks in advance.

1 Reply
Established Member

Re: How send email document attachment using workflow service task

I think that Activiti workflow cannot access repository internally through services. It has to use external APIs.

But just created file don't exist for external APIs.

I found solution in putting document into ASSOC_PACKAGE_CONTAINS as binary array.