0

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

1.发送电子邮件委托

            /*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

4

1 回答 1

0

您需要使用您自己的代码覆盖 Existing MailActionExecuter 类,其中附件将起作用。

覆盖 Bean:

<bean id="custom-mail"  class="org.alfresco.MailActionExecuterWithAttachments" parent="action-executer"> 
    ......
</bean> 
于 2020-05-21T03:57:59.397 回答