1 17 package org.alfresco.repo.action.executer; 18 19 import java.util.List ; 20 21 import org.alfresco.repo.action.ParameterDefinitionImpl; 22 import org.alfresco.service.cmr.action.Action; 23 import org.alfresco.service.cmr.action.ParameterDefinition; 24 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 25 import org.alfresco.service.cmr.repository.NodeRef; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.springframework.mail.SimpleMailMessage; 29 import org.springframework.mail.javamail.JavaMailSender; 30 31 36 public class MailActionExecuter extends ActionExecuterAbstractBase 37 { 38 private static Log logger = LogFactory.getLog(MailActionExecuter.class); 39 40 43 public static final String NAME = "mail"; 44 public static final String PARAM_TO = "to"; 45 public static final String PARAM_SUBJECT = "subject"; 46 public static final String PARAM_TEXT = "text"; 47 48 51 public static final String FROM_ADDRESS = "alfresco_repository@alfresco.org"; 52 53 56 private JavaMailSender javaMailSender; 57 58 63 public void setMailService(JavaMailSender javaMailSender) 64 { 65 this.javaMailSender = javaMailSender; 66 } 67 68 71 @Override 72 protected void executeImpl( 73 Action ruleAction, 74 NodeRef actionedUponNodeRef) 75 { 76 SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); 78 simpleMailMessage.setTo((String )ruleAction.getParameterValue(PARAM_TO)); 79 simpleMailMessage.setSubject((String )ruleAction.getParameterValue(PARAM_SUBJECT)); 80 simpleMailMessage.setText((String )ruleAction.getParameterValue(PARAM_TEXT)); 81 simpleMailMessage.setFrom(FROM_ADDRESS); 82 83 try 84 { 85 javaMailSender.send(simpleMailMessage); 87 } 88 catch (Throwable e) 89 { 90 logger.error("Failed to send email to " + (String )ruleAction.getParameterValue(PARAM_TO), e); 92 } 93 } 94 95 98 @Override 99 protected void addParameterDefintions(List <ParameterDefinition> paramList) 100 { 101 paramList.add(new ParameterDefinitionImpl(PARAM_TO, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_TO))); 102 paramList.add(new ParameterDefinitionImpl(PARAM_SUBJECT, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_SUBJECT))); 103 paramList.add(new ParameterDefinitionImpl(PARAM_TEXT, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_TEXT))); 104 } 105 106 } 107 | Popular Tags |