AnsweredAssumed Answered

Envoyer mail en utilisant TaskListener

Question asked by inaam on Jan 17, 2017
Latest reply on Jan 18, 2017 by inaam

Bonjour, tout le monde.

Je suis debutant en alfresco. J'essaye d'envoyer un mail en utilisant une classe java qui imlpemente TaskListener

 

 

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.context.Context;
import org.alfresco.repo.action.executer.MailActionExecuter;
import org.alfresco.repo.workflow.activiti.ActivitiConstants;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MailSender implements TaskListener {
private static final long serialVersionUID = 1L;

private static final String FROM_ADDRESS = "alfresco@localhost";
private static final String SUBJECT = "Workflow task requires action";
private static final String RECIP_PROCESS_VARIABLE = "ibenchhida@cni.tn"; 

private static Log logger = LogFactory.getLog(MailSender.class);

@Override
public void notify(DelegateTask task) {
logger.debug("Inside ExternalReviewNotification.notify()");
logger.debug("Task ID:" + task.getId());
logger.debug("Task name:" + task.getName());
logger.debug("Task proc ID:" + task.getProcessInstanceId());
logger.debug("Task def key:" + task.getTaskDefinitionKey());


StringBuffer sb = new StringBuffer();
sb.append("You have been assigned to a task named ");
sb.append(task.getName());
//sb.append(". Take the appropriate action by clicking one of the links below:\r\n\r\n");
//sb.append(getLink(task.getId(), "Approve"));
//sb.append(getLink(task.getId(), "Reject"));

logger.debug("Message body:" + sb.toString());

ActionService actionService = getServiceRegistry().getActionService();
Action mailAction = actionService.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, MailSender.SUBJECT);
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, RECIP_PROCESS_VARIABLE); 
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, MailSender.FROM_ADDRESS);
mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, sb.toString());

actionService.executeAction(mailAction, null);

logger.debug("Mail action executed");

return;
}
/*
public String getLink(String taskId, String outcome) {
StringBuffer sb = new StringBuffer();
sb.append("\r\n");
sb.append("http://localhost:8181/alfresco/service/someco/bpm/review?id=activiti$");
sb.append(taskId);
sb.append("&action=");
sb.append(outcome);
sb.append("&guest=true");
sb.append("\r\n\r\n");
return sb.toString();
}*/

/* taken from ActivitiScriptBase.java */
protected ServiceRegistry getServiceRegistry() {
ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
if (config != null) {
// Fetch the registry that is injected in the activiti spring-configuration
ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
if (registry == null) {
throw new RuntimeException(
"Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" +
ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
}
return registry;
}
throw new IllegalStateException("No ProcessEngineCOnfiguration found in active context");
}
}

 

La configuration du alfresco-global.proporties

 

mail.host=zimbra.cni.tn
mail.port=25
mail.username=ibenchhida@cni.tn
mail.password=*********
mail.encoding=UTF-8
mail.from.default=ibenchhida@cni.tn
mail.smtp.auth=false
mail.smtp.timeout=30000

 

mon fichier  .bpmn 

 

<userTask id="usertask3" name="mail au fonctionnaire date prévu de livraison" activiti:assignee="${initiator.properties.userName}">
<extensionElements>
<activiti:taskListener event="create" class="tn.mincom.mail.sender.MailSender"></activiti:taskListener>
</extensionElements>
</userTask>

 

But i am having this Error

 

 

ERROR [action.executer.MailActionExecuter] [http-apr-8181-exec-8] Failed to send email to ibenchhida@cni.tn : org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: zimbra.cni.tn, 25; timeout -1;
nested exception is:
java.net.UnknownHostException: zimbra.cni.tn. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: zimbra.cni.tn, 25; timeout -1;
nested exception is:
java.net.UnknownHostException: zimbra.cni.tn; message exceptions (1) are:
Failed message 1: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: zimbra.cni.tn, 25; timeout -1;
nested exception is:
java.net.UnknownHostException: zimbra.cni.tn
2017-01-17 10:48:01,979 DEBUG [repo.jscript.ScriptLogger] [http-apr-8181-exec-8] org.alfresco.service.cmr.workflow.WorkflowException: 00170022 Impossible de démarrer le workflow activiti$docAdmin:1:8104.

 

 

 

 

Sachant que je suis conncte avec un proxy, veuillez bien me donner un coup de main.

Outcomes