如何将文件附加到电子邮件?户外

How to attach a file to emails? Alfresco

如何将文件(例如工作流 packageItems 文件)附加到电子邮件? 我尝试使用此代码,但未附加文件。我究竟做错了什么?如何将文件附加到电子邮件?

1.SendEmailDelegate

            /*MailWithAttachmentActionExecuter*/
            ActionService actionService = getServiceRegistry().getActionService();
            Action mailAction = actionService.createAction(MailWithAttachmentActionExecuter.NAME);
            mailAction.setParameterValue(MailWithAttachmentActionExecuter.PARAM_SUBJECT, SendEmailDelegate.SUBJECT);
            mailAction.setParameterValue(MailWithAttachmentActionExecuter.PARAM_TO_MANY, recipients);
            mailAction.setParameterValue(MailWithAttachmentActionExecuter.PARAM_FROM, SendEmailDelegate.FROM_ADDRESS);
            mailAction.setParameterValue(MailWithAttachmentActionExecuter.PARAM_TEXT, sb.toString());

            List<NodeRef> attachements = new ArrayList<>();         
            NodeRef workflowPackage = ((ActivitiScriptNode) task.getVariables().get("bpm_package")).getNodeRef();
            //TODOD add noderefs to attachements list... 

            if (workflowPackage != null) {
                NodeService nodeService = getServiceRegistry().getNodeService();

                List<ChildAssociationRef> assocs = nodeService.getChildAssocs(workflowPackage);
                NodeRef[] docs = new NodeRef[assocs.size()];
                if (assocs.size() != 0) {
                    int index = 0;
                    for (ChildAssociationRef assoc : assocs) {
                        docs[index] = assoc.getChildRef();
                        attachements.add(assoc.getChildRef());
                        index++;
                        getServiceRegistry().getPermissionService().setInheritParentPermissions(assoc.getChildRef(), false);
                        getServiceRegistry().getPermissionService().setPermission(assoc.getChildRef(), PermissionService.ALL_AUTHORITIES, PermissionService.CONSUMER, true);
                        getServiceRegistry().getPermissionService().setInheritParentPermissions(assoc.getChildRef(), true);
                    }
                }
                mailAction.setParameterValue(MailWithAttachmentActionExecuter.PARAM_ATTACHMENTS, docs);

            }
            mailAction.setParameterValue(MailWithAttachmentActionExecuter.PARAM_SUBJECT, SendEmailDelegate.SUBJECT);
            mailAction.setParameterValue(MailWithAttachmentActionExecuter.PARAM_TEXT, sb.toString());
            //actionService.executeAction(mailAction, null);
            actionService.executeAction(mailAction, null, false, sendEmailAsynchronously);
            logger.debug("MailWithAttachmentActionExecuter executed");

2。 MailWithAttachmentActionExecuter MailWithAttachmentActionExecuter

您需要使用您自己的代码覆盖现有的 MailActionExecuter class,附件才能正常工作。

覆盖 Bean:

<bean id="custom-mail"  class="org.alfresco.MailActionExecuterWithAttachments" parent="action-executer"> 
    ......
</bean>