mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Fix for AR-636
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3034 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -98,6 +98,9 @@
|
|||||||
<property name="password">
|
<property name="password">
|
||||||
<value>${mail.password}</value>
|
<value>${mail.password}</value>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="defaultEncoding">
|
||||||
|
<value>${mail.encoding}</value>
|
||||||
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- -->
|
<!-- -->
|
||||||
|
@@ -63,6 +63,8 @@ mail.host=
|
|||||||
mail.port=25
|
mail.port=25
|
||||||
mail.username=anonymous
|
mail.username=anonymous
|
||||||
mail.password=
|
mail.password=
|
||||||
|
# Set this value to UTF-8 or similar for encoding of email messages as required
|
||||||
|
mail.encoding=
|
||||||
|
|
||||||
# System Configuration
|
# System Configuration
|
||||||
|
|
||||||
|
@@ -23,9 +23,11 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.mail.MessagingException;
|
||||||
|
import javax.mail.internet.MimeMessage;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.action.ParameterDefinitionImpl;
|
import org.alfresco.repo.action.ParameterDefinitionImpl;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationException;
|
|
||||||
import org.alfresco.repo.template.DateCompareMethod;
|
import org.alfresco.repo.template.DateCompareMethod;
|
||||||
import org.alfresco.repo.template.HasAspectMethod;
|
import org.alfresco.repo.template.HasAspectMethod;
|
||||||
import org.alfresco.repo.template.I18NMessageMethod;
|
import org.alfresco.repo.template.I18NMessageMethod;
|
||||||
@@ -33,7 +35,6 @@ import org.alfresco.service.ServiceRegistry;
|
|||||||
import org.alfresco.service.cmr.action.Action;
|
import org.alfresco.service.cmr.action.Action;
|
||||||
import org.alfresco.service.cmr.action.ParameterDefinition;
|
import org.alfresco.service.cmr.action.ParameterDefinition;
|
||||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.repository.TemplateNode;
|
import org.alfresco.service.cmr.repository.TemplateNode;
|
||||||
@@ -44,8 +45,9 @@ import org.alfresco.service.cmr.security.AuthorityType;
|
|||||||
import org.alfresco.service.cmr.security.PersonService;
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
|
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||||
|
import org.springframework.mail.javamail.MimeMessagePreparator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mail action executor implementation.
|
* Mail action executor implementation.
|
||||||
@@ -168,100 +170,106 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void executeImpl(
|
protected void executeImpl(
|
||||||
Action ruleAction,
|
final Action ruleAction,
|
||||||
NodeRef actionedUponNodeRef)
|
final NodeRef actionedUponNodeRef)
|
||||||
{
|
{
|
||||||
// Create the simple mail message
|
// Create the mime mail message
|
||||||
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
|
MimeMessagePreparator mailPreparer = new MimeMessagePreparator()
|
||||||
|
|
||||||
// set recipient
|
|
||||||
String to = (String)ruleAction.getParameterValue(PARAM_TO);
|
|
||||||
if (to != null && to.length() != 0)
|
|
||||||
{
|
{
|
||||||
simpleMailMessage.setTo(to);
|
public void prepare(MimeMessage mimeMessage) throws MessagingException
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// see if multiple recipients have been supplied - as a list of authorities
|
|
||||||
List<String> authorities = (List<String>)ruleAction.getParameterValue(PARAM_TO_MANY);
|
|
||||||
if (authorities != null && authorities.size() != 0)
|
|
||||||
{
|
{
|
||||||
List<String> recipients = new ArrayList<String>(authorities.size());
|
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
|
||||||
for (String authority : authorities)
|
|
||||||
|
// set recipient
|
||||||
|
String to = (String)ruleAction.getParameterValue(PARAM_TO);
|
||||||
|
if (to != null && to.length() != 0)
|
||||||
{
|
{
|
||||||
AuthorityType authType = AuthorityType.getAuthorityType(authority);
|
message.setTo(to);
|
||||||
if (authType.equals(AuthorityType.USER))
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// see if multiple recipients have been supplied - as a list of authorities
|
||||||
|
List<String> authorities = (List<String>)ruleAction.getParameterValue(PARAM_TO_MANY);
|
||||||
|
if (authorities != null && authorities.size() != 0)
|
||||||
{
|
{
|
||||||
if (this.personService.personExists(authority) == true)
|
List<String> recipients = new ArrayList<String>(authorities.size());
|
||||||
|
for (String authority : authorities)
|
||||||
{
|
{
|
||||||
NodeRef person = this.personService.getPerson(authority);
|
AuthorityType authType = AuthorityType.getAuthorityType(authority);
|
||||||
String address = (String)this.nodeService.getProperty(person, ContentModel.PROP_EMAIL);
|
if (authType.equals(AuthorityType.USER))
|
||||||
if (address != null && address.length() != 0)
|
|
||||||
{
|
{
|
||||||
recipients.add(address);
|
if (personService.personExists(authority) == true)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (authType.equals(AuthorityType.GROUP))
|
|
||||||
{
|
|
||||||
// else notify all members of the group
|
|
||||||
Set<String> users = this.authorityService.getContainedAuthorities(AuthorityType.USER, authority, false);
|
|
||||||
for (String userAuth : users)
|
|
||||||
{
|
|
||||||
if (this.personService.personExists(userAuth) == true)
|
|
||||||
{
|
|
||||||
NodeRef person = this.personService.getPerson(authority);
|
|
||||||
String address = (String)this.nodeService.getProperty(person, ContentModel.PROP_EMAIL);
|
|
||||||
if (address != null && address.length() != 0)
|
|
||||||
{
|
{
|
||||||
recipients.add(address);
|
NodeRef person = personService.getPerson(authority);
|
||||||
|
String address = (String)nodeService.getProperty(person, ContentModel.PROP_EMAIL);
|
||||||
|
if (address != null && address.length() != 0)
|
||||||
|
{
|
||||||
|
recipients.add(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (authType.equals(AuthorityType.GROUP))
|
||||||
|
{
|
||||||
|
// else notify all members of the group
|
||||||
|
Set<String> users = authorityService.getContainedAuthorities(AuthorityType.USER, authority, false);
|
||||||
|
for (String userAuth : users)
|
||||||
|
{
|
||||||
|
if (personService.personExists(userAuth) == true)
|
||||||
|
{
|
||||||
|
NodeRef person = personService.getPerson(authority);
|
||||||
|
String address = (String)nodeService.getProperty(person, ContentModel.PROP_EMAIL);
|
||||||
|
if (address != null && address.length() != 0)
|
||||||
|
{
|
||||||
|
recipients.add(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message.setTo(recipients.toArray(new String[recipients.size()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
simpleMailMessage.setTo(recipients.toArray(new String[recipients.size()]));
|
// set subject line
|
||||||
|
message.setSubject((String)ruleAction.getParameterValue(PARAM_SUBJECT));
|
||||||
|
|
||||||
|
// See if an email template has been specified
|
||||||
|
String text = null;
|
||||||
|
NodeRef templateRef = (NodeRef)ruleAction.getParameterValue(PARAM_TEMPLATE);
|
||||||
|
if (templateRef != null)
|
||||||
|
{
|
||||||
|
// build the email template model
|
||||||
|
Map<String, Object> model = createEmailTemplateModel(actionedUponNodeRef);
|
||||||
|
|
||||||
|
// process the template against the model
|
||||||
|
text = templateService.processTemplate("freemarker", templateRef.toString(), model);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the text body of the message
|
||||||
|
if (text == null)
|
||||||
|
{
|
||||||
|
text = (String)ruleAction.getParameterValue(PARAM_TEXT);
|
||||||
|
}
|
||||||
|
message.setText(text);
|
||||||
|
|
||||||
|
// set the from address - use the default if not set
|
||||||
|
String from = (String)ruleAction.getParameterValue(PARAM_FROM);
|
||||||
|
if (from != null)
|
||||||
|
{
|
||||||
|
message.setFrom(from);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message.setFrom(FROM_ADDRESS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// set subject line
|
|
||||||
simpleMailMessage.setSubject((String)ruleAction.getParameterValue(PARAM_SUBJECT));
|
|
||||||
|
|
||||||
// See if an email template has been specified
|
|
||||||
String text = null;
|
|
||||||
NodeRef templateRef = (NodeRef)ruleAction.getParameterValue(PARAM_TEMPLATE);
|
|
||||||
if (templateRef != null)
|
|
||||||
{
|
|
||||||
// build the email template model
|
|
||||||
Map<String, Object> model = createEmailTemplateModel(actionedUponNodeRef);
|
|
||||||
|
|
||||||
// process the template against the model
|
|
||||||
text = templateService.processTemplate("freemarker", templateRef.toString(), model);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the text body of the message
|
|
||||||
if (text == null)
|
|
||||||
{
|
|
||||||
text = (String)ruleAction.getParameterValue(PARAM_TEXT);
|
|
||||||
}
|
|
||||||
simpleMailMessage.setText(text);
|
|
||||||
|
|
||||||
// set the from address - use the default if not set
|
|
||||||
String from = (String)ruleAction.getParameterValue(PARAM_FROM);
|
|
||||||
if (from != null)
|
|
||||||
{
|
|
||||||
simpleMailMessage.setFrom(from);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
simpleMailMessage.setFrom(FROM_ADDRESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Send the message
|
// Send the message
|
||||||
javaMailSender.send(simpleMailMessage);
|
javaMailSender.send(mailPreparer);
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user