【问题标题】:How to attach a file to emails? Alfresco如何将文件附加到电子邮件?露天
【发布时间】:2020-05-20 13:34:14
【问题描述】:

如何将文件(例如,工作流 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

【问题讨论】:

  • 我认为您可能需要在自定义覆盖 bean 中覆盖 the prepareEmail method,然后在自定义代码中检查另一个参数 + 将其附加到 MimeMessage - 看不到任何额外的参数默认可以设置的代码
  • @Gagravarr!当我覆盖 prepareEmail 方法时,它向我显示以下错误ERROR [repo.action.AsynchronousActionExecutionQueueImpl] [defaultAsyncAction2] Failed to execute asynchronous action: Action[ id=7bcde69f-214b-4f61-b76a-100454c36e5a, node=null ] java.lang.NullPointerException at CustomMailActionExecuter.java:1345, CustomMailActionExecuter.java:1171,CustomMailActionExecuter.java:544,CustomMailActionExecuter.java:482 对不起,您能指导我更多吗?
  • 在您的自定义代码中查找该行是什么,并找出哪个对象为空?
  • 谢谢@Gagravarr,我解决了这个错误。

标签: alfresco alfresco-webscripts alfresco-maven


【解决方案1】:

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

覆盖 Bean:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-25
    • 1970-01-01
    • 1970-01-01
    • 2019-01-21
    • 2015-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多