SharePoint 2010: Email event reciever not working in a farm

I came across and interesting issue earlier this week while investigating a deployment of a custom solution to a client, this solution revolved around processing incoming emails and updating sharepoint list items accordingly, using an ‘SPEmailEventReceiver’ object.

The Solution was set to deploy to a specific web application, OOTB libraries configured to send emails worked perfectly but although emails sent to our event enabled custom libraries failed to record the email or input the files into the library

Through hours of debugging only to find the custom code was not being fired at any stage, the farm was configured correctly, and everything else was working as expected

Then I had an epiphany, where was the incoming emails configured to come into the farm, it turns out an application server was processing the emails and sending them into sharepoint but the solution was only deployed to a WFE? that means that the application server processing the email isn’t aware of the custom event handler?

Surely not!

The definitions of the event handlers along with the servers they are deployed to are all stored in SharePoint it should be able to pass that request onto a server with the event receiver definition right?? Not, as it turns out! SharePoint was rejecting everything that interacted with the event receiver as it couldn’t find it and activate it on the app server

The Solution

The solution for this is very straight forward, either deploy your solution to a webapp on the application server or modify the manifest of the solution so it can point to application servers as well, in our case the custom solution contained web app specific functionality so it wasn’t possible to make this globally deployable