diff --git a/src/main/java/org/alfresco/repo/action/executer/MailActionExecuter.java b/src/main/java/org/alfresco/repo/action/executer/MailActionExecuter.java index 07d46f2751..c7a1168f7b 100644 --- a/src/main/java/org/alfresco/repo/action/executer/MailActionExecuter.java +++ b/src/main/java/org/alfresco/repo/action/executer/MailActionExecuter.java @@ -614,11 +614,13 @@ public class MailActionExecuter extends ActionExecuterAbstractBase } // set recipient - String to = (String)ruleAction.getParameterValue(PARAM_TO); + String to = (String)ruleAction.getParameterValue(PARAM_TO); + String toRecipients = null; if (to != null && to.length() != 0) { messageRef[0].setTo(to); - + toRecipients = to; + // Note: there is no validation on the username to check that it actually is an email address. // TODO Fix this. @@ -777,7 +779,8 @@ public class MailActionExecuter extends ActionExecuterAbstractBase if(recipients.size() > 0) { - messageRef[0].setTo(recipients.toArray(new String[recipients.size()])); + messageRef[0].setTo(recipients.toArray(new String[recipients.size()])); + toRecipients = String.join(",", recipients); } else { @@ -925,7 +928,7 @@ public class MailActionExecuter extends ActionExecuterAbstractBase } // build the email template model - Map model = createEmailTemplateModel(actionedUponNodeRef, suppliedModel, fromPerson); + Map model = createEmailTemplateModel(actionedUponNodeRef, suppliedModel, fromPerson, toRecipients); // Determine the locale to use to send the email. Locale locale = recipient.getSecond(); @@ -1500,15 +1503,20 @@ public class MailActionExecuter extends ActionExecuterAbstractBase * * @return Model map for email templates */ - private Map createEmailTemplateModel(NodeRef ref, Map suppliedModel, NodeRef fromPerson) + private Map createEmailTemplateModel(NodeRef ref, Map suppliedModel, NodeRef fromPerson, String toRecipents) { Map model = new HashMap(8, 1.0f); if (fromPerson != null) { model.put("person", new TemplateNode(fromPerson, serviceRegistry, null)); - } - + } + + if (toRecipents != null) + { + model.put("to", toRecipents); + } + if (ref != null) { model.put("document", new TemplateNode(ref, serviceRegistry, null)); diff --git a/src/test/java/org/alfresco/repo/action/executer/AbstractMailActionExecuterTest.java b/src/test/java/org/alfresco/repo/action/executer/AbstractMailActionExecuterTest.java index ee705a0523..d2d6513b93 100644 --- a/src/test/java/org/alfresco/repo/action/executer/AbstractMailActionExecuterTest.java +++ b/src/test/java/org/alfresco/repo/action/executer/AbstractMailActionExecuterTest.java @@ -792,17 +792,18 @@ public abstract class AbstractMailActionExecuterTest AUTHORITY_SERVICE.addAuthority(groupName, USER1); AUTHORITY_SERVICE.addAuthority(groupName, USER2); - // Prepare email to be sent to group. Add also a template + // Create mail final Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME); mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "some.body@example.com"); mailAction.setParameterValue(MailActionExecuter.PARAM_TO_MANY, groupName); mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing"); mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "Testing"); - mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, "alfresco/templates/mail/test.txt.ftl"); - mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) getModel()); + mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, "alfresco/templates/mail/testSentTo.txt.ftl"); - // Send email - MimeMessage message = TRANSACTION_SERVICE.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() + RetryingTransactionHelper txHelper = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class); + + // Send mail + MimeMessage message = txHelper.doInTransaction(new RetryingTransactionCallback() { @Override public MimeMessage execute() throws Throwable @@ -810,13 +811,12 @@ public abstract class AbstractMailActionExecuterTest ACTION_EXECUTER.executeImpl(mailAction, null); return ACTION_EXECUTER.retrieveLastTestMessage(); } - }); + }, true); - // Check that both users are displayed in TO field - Address[] addresses = message.getRecipients(Message.RecipientType.TO); - Assert.assertEquals("Expected both users to be in TO field", 2, addresses.length); - Assert.assertEquals(USER1 + "@email.com", addresses[0].toString()); - Assert.assertEquals(USER2 + "@email.com", addresses[1].toString()); + // Check that both users are displayed in message body + String recipients = USER1 + "@email.com" + "," + USER2 + "@email.com"; + Assert.assertNotNull(message); + Assert.assertEquals("This email was sent to " + recipients, (String) message.getContent()); } finally { diff --git a/src/test/resources/alfresco/templates/mail/testSentTo.txt.ftl b/src/test/resources/alfresco/templates/mail/testSentTo.txt.ftl new file mode 100644 index 0000000000..7e4bd7c87a --- /dev/null +++ b/src/test/resources/alfresco/templates/mail/testSentTo.txt.ftl @@ -0,0 +1 @@ +This email was sent to ${to} \ No newline at end of file