Override out-of-the box "mail" Repo-tier action

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member II

Override out-of-the box "mail" Repo-tier action

Hi, folks! In my project I have a requirement to be able to send emails with attachments. I know that there is a sample implementation of custom action "Send-As-Email", but I needed to override standard "mail" action in such a way that it could send documents as attachents.

Ok, "mail" action is described as a proxy bean in action-services-context.xml. Actual "mail" bean is described in outboundSMTP-context.xml.

What I did in Alfresco 5.1 is just overrided outboundSMTP subsystem whith my own implementation of "mail" bean. Everything worked as I expected untill I migrated to Alfresco 6.1.

In Alfresco 6.1 the same approach produced an unexpected behaviour. There was no errors on startup and context initialization, but when I tried to create a "Send email" rule Repo-tier thrown an exception during rule saving:

2019-11-22 14:50:00,932 ERROR [org.springframework.extensions.webscripts.AbstractRuntime] [http-nio-9090-exec-7] Exception from executeScript: 10220002 Wrapped Exception (with status template): object is not an instance of declaring class

After a debugging session and digging into Alfresco source code I've figured out the only difference between 5.1 and 6.1 in regard of Repo-tier "mail" action defenition is in action-services-context.xml:

Alfresco 5.1:

<!-- Import mail action executor from the OutboundSMTP subsystem -->
<bean id="mail" class="org.alfresco.repo.management.subsystems.SubsystemProxyFactory">
<property name="sourceApplicationContextFactory">
<ref bean="OutboundSMTP" />
</property>
<property name="interfaces">
<list>
<value>org.alfresco.repo.action.executer.ActionExecuter</value>
<value>org.alfresco.repo.action.executer.TestModeable</value>
</list>
</property>
</bean>

 In Alfresco 6.1:

<!-- Import mail action executor from the OutboundSMTP subsystem -->
<bean id="mail" class="org.alfresco.repo.management.subsystems.SubsystemProxyFactory">
<property name="sourceApplicationContextFactory">
<ref bean="OutboundSMTP" />
</property>
<property name="sourceBeanName">
<value>mail</value>
</property>
<property name="interfaces">
<list>
<value>org.alfresco.repo.action.executer.ActionExecuter</value>
<value>org.alfresco.repo.action.executer.TestModeable</value>
</list>
</property>
</bean>

 As you see in Alfresco 6.1 they've added sourceBeanName property (actually it is optional). Somehow this broke my code. To fix it I had to additionally override that proxy "mail" bean from action-services-context.xml in a way it was in Alfresco 5.1 (without sourceBeanName property). And everything worked fine again. 

Can someone explain me this wierd behaviuor?

3 Replies
Highlighted
Moderator
Moderator

Re: Override out-of-the box "mail" Repo-tier action

OOTB MailExecutorAction doesn't allow sending the attachment with emails. Refer this post, rjohnson has an example of overriden action to handle attachement. 

https://hub.alfresco.com/t5/alfresco-content-services-hub/send-html-mail-with-attachments/ba-p/28999...

Highlighted
Active Member II

Re: Override out-of-the box "mail" Repo-tier action

Yes, I know that Alfresco doesn't support attachments OOTB. And I was able to override OOTB "mail" action in 5.1 by just overriding "mail" bean in outboundSMTP-context.xml. But in 6.1 it was not enough to make it work, I had to additionaly override proxy-bean from action-services-context.xml.

My point was that it looks odd that one need to additionaly override proxy-bean to make overriden action work.

Anyway, thanks!

Highlighted
Moderator
Moderator

Re: Override out-of-the box "mail" Repo-tier action

I would suggest to extend the mail executor action instead of overriding the context files unless there is something you are not able to achieve by extending mail executor action. I shared a sample in my last reply. You may consider looking into that as well.