cancel
Showing results for 
Search instead for 
Did you mean: 

How to trigger an action with java?

elcamino
Confirmed Champ
Confirmed Champ

Alfresco Community (Build: 201707)
===============================

Contains:
    - Alfresco Platform:    5.2.g
    - Alfresco Share:        5.2.f

alfresco-global.properties:

### Outbound SMTP configuration properties - Working example ###
# Sample Gmail settings
mail.host=smtp.gmail.com
mail.port=465
mail.username=elcamino@gmail.com
mail.password=*********
mail.protocol=smtps
mail.smtps.starttls.enable=true
mail.smtps.auth=true

Project dependency:
compile group: 'org.alfresco', name: 'alfresco-repository', version: '6.50'  // https://mvnrepository.com..

Hello

I would like to send a test email with the alfresco built in "send email" action.

What are the theoretical steps needed to do so ?

1. Include alfresco-repository dependency in the project

2. Create _Alfresco_sendmail() method (see test code below)

3. And now im a little lost, what next ?

3.1. As you notice there is no authentication hire, what is the logic behind the authentication user pass server ip Where to put those? From what I understand I can not do it with CMIS1.1

Hire is my test code.

public void alfrescoSendMail() {'   // replaced _Alfresco_sendmail() with alfrescoSendMail
ActionService actionService = serviceRegistry.getActionService();
Action mailAction = actionService.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Hello Mathew!");
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, "elcamino@zmail.com");
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "alfresco@bsa.com.au");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "Test message!");
actionService.executeAction(mailAction, null);
}
4 REPLIES 4

jpotts
World-Class Innovator
World-Class Innovator

You have the right idea. The question I have is, what do you want to trigger this code? Your method looks right (except for the method name, which should look more like "alfrescoSendMail"). But what class is your method in?

 * Is this an action executer that you are calling from a folder rule? (See Actions Tutorial).

 * Or is this a web script controller that you are invoking via REST? (See Web Script Tutorial).

 * Or is this a behavior that you have bound to a policy to trigger when something happens to a node of a certain type or with a certain aspect? (See Behavior Tutorial).

Once you have decided what will trigger your email, you can put your method in a class that extends the appropriate parent class, then you can package your JAR up as an AMP and use the MMT to merge it with your Alfresco WAR (See Maven SDK Tutorial).

Use case:

1. So basically I have an example jHipster java/angular project & Alfresco server.

2. I can add/pull files to/from Alfreesco repo via CMIS 1.1 & atompub URL

3. I can receive emails with attachments into alfresco

3. Now I would like to take received email with an attachment & send it to lets say to my Gmail account

If I understood correctly then Alfresco Share comes with a built in "Send Email" action. (This action can be triggered with a folder rule for example).

1. Is it possible to trigger this "Send Email" action with a custom java code?

For example:

1. Generate an example "Hello world" project (maven+java+Spring Boot) at Spring Initializr website

2. Inside this project call alfrescoSendMail();

3. This method then should connect to Alfresco serverSmiley Tongueort, authenticate, pass in parameters like (subject, to , from, message, attachments).

Or would it be simpler to just pull the files from alfresco repo via CMIS 1.1 & then use java functionality (click this link) to send the emails instead ?

douglascrp
World-Class Innovator
World-Class Innovator

Hello.

The Java service you used in your code is intended to be used in the Alfresco process, and not from outside.

In order to achieve what you need, I would use the webscript way (the link Jeff shared) and then, with the method exposed, use anything you want to execute it via REST, passing on the parameters you already have.

Your custom webscript would have the code you shared as part of it.

jpotts
World-Class Innovator
World-Class Innovator

Either way it is Java code, so I don't think one is easier or harder than the other. From an architectural perspective it seems to me that Alfresco might be the right place to send the email because it is also the system receiving the email. On the other hand, if your JHipster app needs to do some processing, then maybe your JHipster app should send the email.

If you decide to send the email from Alfresco you have to decide what triggers the email to be sent. If you need it to be triggered from your JHipster app, then write a web script and trigger it by calling the webscript's URL from the JHipster app.

If you decide to send the email from JHipster, use CMIS to grab the files, then send it from there using whatever Java API you want.