cancel
Showing results for 
Search instead for 
Did you mean: 

prolem with mail sender class

ucf
Champ on-the-rise
Champ on-the-rise
I want to make a java class that sens email, I've found the example given by jeff potts but it just executes the method initialiseHandler, it doesn't execute the mail action in the execute(ExecutionContext executionContext) method, can anyone help?
thank you
8 REPLIES 8

mrogers
Star Contributor
Star Contributor
Alfresco already has an email action.   You could take a look at that or follow a tutorial on the java mail API.

kaynezhang
World-Class Innovator
World-Class Innovator

First define ServiceRegistry field in your class

private ServiceRegistry serviceRegistry ;

Then get serviceRegistry  in initialiseHandler() method

this.serviceRegistry = (ServiceRegistry)factory.getBean(ServiceRegistry.SERVICE_REGISTRY);

Last ,send email using mail actin in execute() method

ActionService actionService = serviceRegistry.getActionService();
Action mail = actionService.createAction(MailActionExecuter.NAME);

mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT, subject);       
mail.setParameterValue(MailActionExecuter.PARAM_TO, recipient);
mail.setParameterValue(MailActionExecuter.PARAM_FROM, from address);
mail.setParameterValue(MailActionExecuter.PARAM_TEXT, body text);
actionService.executeAction(mail, null);

ucf
Champ on-the-rise
Champ on-the-rise
thanks but the problem is that it doesn't even enter in execute() method, I wote a System.out.println() to check, it was negative

kaynezhang
World-Class Innovator
World-Class Innovator
Have you configured your class in your process definition xml file?
And you class must inherit from org.alfresco.repo.workflow.jbpm.JBPMSpringActionHandler

ucf
Champ on-the-rise
Champ on-the-rise
yes I actually did extends JBPMSpringActionHandler and added the bean of the class in the services-context.xml and in processDefinition.xml as an action inside a task node

kaynezhang
World-Class Innovator
World-Class Innovator
Please paste your process definition here.You should configure full class name in process definition,like following

<action class="**.****.***.YourAction" />

ucf
Champ on-the-rise
Champ on-the-rise
Thanks a lot for your help, it turned out that the workflow wasn't starting well, problem solved thank you

kaynezhang
World-Class Innovator
World-Class Innovator
If you just want to send email in action handler ,you can also use
org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript 
which is a jBPM action handler for executing alfresco Script